- 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 4378 Articles for MySQL
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
601 Views
If your first column is AUTO_INCREMENT, then you can skip the column and place the value NULL. Let us first create a table −mysql> create table DemoTable ( StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, StudentFirstName varchar(100), StudentAge int ); Query OK, 0 rows affected (0.60 sec)Insert some records in the table using insert command. Here, we have skipped the first column, since it is AUTO_INCREMENT −mysql> insert into DemoTable values(NULL, 'Robert', 21); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable values(NULL, 'Sam', 22); Query OK, 1 row affected (0.18 sec) mysql> insert into ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
64 Views
To optimize many SELECTs, use it once and apply IN() to fetch multiple values. Let us first create a table −mysql> create table DemoTable ( Id int, Name varchar(100), Age int ); Query OK, 0 rows affected (0.77 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(1, 'Chris', 23); Query OK, 1 row affected (0.39 sec) mysql> insert into DemoTable values(2, 'David', 21); Query OK, 1 row affected (0.56 sec) mysql> insert into DemoTable values(3, 'Mike', 24); Query OK, 1 row affected (0.28 sec) mysql> insert into DemoTable values(4, 'Robert', 22); Query ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
754 Views
To count the duplicate ID values, use aggregate function COUNT() and GROUP BY. Let us first create a table −mysql> create table DemoTable ( Id int, Name varchar(100) ); Query OK, 0 rows affected (1.30 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(50, 'Chris'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values(51, 'David'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values(51, 'Mike'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values(50, 'Sam'); Query OK, 1 row affected (0.17 sec)Display all records ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
395 Views
Let us first create a table −mysql> create table DemoTable1 ( Id int, Name varchar(100) ); Query OK, 0 rows affected (0.86 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1 values(1001, 'Chris'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable1 values(999, 'Robert'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1 values(1003, 'Mike'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable1 values(1002, 'Sam'); Query OK, 1 row affected (0.13 sec)Display all records from the table using select statement −mysql> select *from DemoTable1;This will produce the ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
212 Views
For this, you can use round() along with avg(). Let us first create a table −mysql> create table DemoTable ( Score int ); Query OK, 0 rows affected (0.68 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(98); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable values(97); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values(91); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values(86); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable values(45); Query OK, 1 row affected (0.12 sec)Display all ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
2K+ Views
There is no difference between TINYINT(1) and Boolean. The keyword Bool or Boolean internally converts into TINYINT(1) or we can say Bool or Boolean are synonymous with TINYINT(1).Let us first create a table −mysql> create table DemoTable ( isMarried Boolean ); Query OK, 0 rows affected (1.77 sec)Let us check the description of the table −mysql> desc DemoTable;This will produce the following output −+-----------+------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-----------+------------+------+-----+---------+-------+ | isMarried | tinyint(1) | YES | | ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
120 Views
For this, use AS select statement. Let us first create a table −mysql> create table DemoTable1 ( Score int ); Query OK, 0 rows affected (1.22 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1 values(89); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable1 values(98); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable1 values(91); Query OK, 1 row affected (0.24 sec)Display all records from the table using select statement −mysql> select *from DemoTable1;This will produce the following output −+-------+ | Score | +-------+ | 89 | ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
74 Views
To find a minimum score from the entire four columns, use MySQL LEAST() function. Let us first create a table −mysql> create table DemoTable( Score1 int, Score2 int, Score3 int, Score4 int ); Query OK, 0 rows affected (0.50 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(88, 76, 45, 56); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable values(99, 78, 87, 34); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values(34, 32, 56, 98); Query OK, 1 row affected (0.44 sec)Display all records from ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
101 Views
To select four random tables, use ORDER BY RAND(). Following is the syntax −select TABLE_NAME AS anyAliasName from INFORMATION_SCHEMA.TABLES where TABLE_SCHEMA = ‘yourDatabaseName’; order by rand() limit yourLimitNumber;Let us implement the above syntax in order to select four random tables from a MySQL database that has thousands of tables.Here, LIMIT is used to set the number of records you want to fetch. Since we want 4 records, therefore we would be using LIMIT 4. Following is the query −mysql> select TABLE_NAME AS Random4TableName from INFORMATION_SCHEMA.TABLES where TABLE_SCHEMA = 'web' order by ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
135 Views
To get the maximum value of a column, MySQL has a predefined aggregate function MAX(). Let us first create a table −mysql> create table DemoTable ( Id int ); Query OK, 0 rows affected (0.96 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(100); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values(988); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values(1000); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values(99); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values(999); Query OK, ... Read More