- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 4219 Articles for MySQLi
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
156 Views
Set the same condition like “OR” in a MySQL CASE expression. Let us first create a sample table.Following is the querymysql> create table caseOrConditionDemo -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> Name varchar(100), -> Score int -> ); Query OK, 0 rows affected (0.49 sec)Following is the query to insert some records in the table using insert command:mysql> insert into caseOrConditionDemo(Name, Score) values('Larry', 85); Query OK, 1 row affected (0.18 sec) mysql> insert into caseOrConditionDemo(Name, Score) values('Sam', 74); Query OK, 1 row affected (0.20 sec) mysql> insert into caseOrConditionDemo(Name, ... Read More
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
149 Views
The variable declaration must be between BEGIN and END. Under BEGIN and END, the first statement must be declaration of variable. After that you can include insert, select, etc.Let us now see an example. Here, the variable name is “output”:mysql> DELIMITER // mysql> CREATE PROCEDURE showVariablesValue() -> BEGIN -> DECLARE output varchar(100); -> SET output="Hello MySQL"; -> SELECT output; -> END -> // Query OK, 0 rows affected (0.25 sec) mysql> DELIMITER ;Now you can call the stored procedure using call ... Read More
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
1K+ Views
Yes, MySQL internally convert bool to tinyint(1) because tinyint is the smallest integer data type.You can also say the bool is synonym for tinyint(1). Let us first create a sample table:mysql> create table boolToTinyIntDemo -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> Name varchar(20), -> isAgeGreaterThan18 bool -> ); Query OK, 0 rows affected (1.02 sec)Let us now check the description of table:mysql> desc boolToTinyIntDemo;This will produce the following output+--------------------+-------------+------+-----+---------+----------------+ | Field ... Read More
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
142 Views
To select one specific row and another random row, you can use ORDER BY and RAND(). Let us first create a sample table:mysql> create table oneSpecificRowAndOtherRandom -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> Name varchar(20) -> ); Query OK, 0 rows affected (0.72 sec)Following is the query to insert some records in the table using insert command:mysql> insert into oneSpecificRowAndOtherRandom(Name) values('Larry'); Query OK, 1 row affected (0.56 sec) mysql> insert into oneSpecificRowAndOtherRandom(Name) values('Sam'); Query OK, 1 row affected (0.13 sec) mysql> insert into oneSpecificRowAndOtherRandom(Name) values('Mike'); Query OK, 1 row affected ... Read More
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
227 Views
In MySQL, AUTO_INCREMENT=3 tells that the inserted record will start from 3 not the default 1. Let us first create a sample table and set auto increment to 3:mysql> create table Auto_incrementDemo -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> Name varchar(20) -> )AUTO_INCREMENT=3; Query OK, 0 rows affected (0.52 sec)Following is the query to insert some records in the table using insert command:mysql> INSERT INTO Auto_incrementDemo(Name) values('John'); Query OK, 1 row affected (0.12 sec) mysql> INSERT INTO Auto_incrementDemo(Name) values('Larry'); Query OK, 1 row affected (0.15 sec) mysql> INSERT INTO Auto_incrementDemo(Name) ... Read More
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
508 Views
To count value for multiple columns, use the CASE statement. Let us first create a table::mysql> create table countValueMultipleColumnsDemo -> ( -> Value1 int, -> Value2 int, -> Value3 int -> ); Query OK, 0 rows affected (0.62 sec)Following is the query to insert some records in the table using insert command:mysql> insert into countValueMultipleColumnsDemo values(10, 15, 10); Query OK, 1 row affected (0.15 sec) mysql> insert into countValueMultipleColumnsDemo values(20, 30, 10); Query OK, 1 row affected (0.14 sec) mysql> insert into countValueMultipleColumnsDemo values(40, 10, 60); Query OK, 1 row affected (0.18 sec)Following ... Read More
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
4K+ Views
To change a primary key to auto_increment, you can use MODIFY command. Let us first create a table.mysql> create table changePrimaryKeyInAutoIncrement -> ( -> StudentId int not null primary key, -> StudentName varchar(100), -> StudentAge int, -> StudentAddress varchar(100) -> ); Query OK, 0 rows affected (0.63 sec)Let us now check the description of table using desc command:mysql> desc changePrimaryKeyInAutoIncrement;This will produce the following output+----------------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +----------------+--------------+------+-----+---------+-------+ | StudentId | int(11) ... Read More
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
545 Views
To get total number of fields in all tables in database, you can use information_schema.columns along with aggregate function count(*).We are using ‘sample’ database which consists of a lot of tables with fields. Following is the query to get total number of fields in all tables in database:mysql> SELECT COUNT(*) AS TOTAL_NUMBER_OF_FIELDS -> FROM INFORMATION_SCHEMA.COLUMNS -> WHERE TABLE_SCHEMA = 'sample';This will produce the following output+------------------------+ | TOTAL_NUMBER_OF_FIELDS | +------------------------+ | 796 | +------------------------+ 1 row in set (0.04 sec)Now, let us check another database ‘test’. Following is the query ... Read More
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
1K+ Views
To convert bool to int in MySQL, you can use CAST(). Let us first create a table:mysql> create table convertBoolToIntDemo -> ( -> isYoung bool -> ); Query OK, 0 rows affected (0.69 sec)Following is the query to insert some records in the table using insert command:mysql> insert into convertBoolToIntDemo values(true); Query OK, 1 row affected (0.18 sec) mysql> insert into convertBoolToIntDemo values(false); Query OK, 1 row affected (0.09 sec) mysql> insert into convertBoolToIntDemo values(true); Query OK, 1 row affected (0.15 sec) mysql> insert into convertBoolToIntDemo values(false); Query ... Read More
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
3K+ Views
To sort by character length in MySQL use the ORDER BY LENGTH(). Let us first create a table:mysql> create table orderingAADemo -> ( -> Value varchar(100) -> ); Query OK, 0 rows affected (1.30 sec)Following is the query to insert some records in the table using insert command:mysql> insert into orderingAADemo values('A'); Query OK, 1 row affected (0.12 sec) mysql> insert into orderingAADemo values('B'); Query OK, 1 row affected (0.13 sec) mysql> insert into orderingAADemo values('AA'); Query OK, 1 row affected (0.20 sec) mysql> insert into orderingAADemo values('C'); Query OK, 1 row affected (0.12 ... Read More