- 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
105 Views
Let us first create a table −mysql> create table DemoTable ( ClientId int NOT NULL AUTO_INCREMENT PRIMARY KEY, ClientName varchar(30) ); Query OK, 0 rows affected (0.74 sec)Insert records in the table using insert command −mysql> insert into DemoTable(ClientName) values('John'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable(ClientName) values('Chris'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable(ClientName) values('Robert'); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable(ClientName) values('David'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable(ClientName) values('Bob'); Query OK, 1 row affected (0.15 sec) mysql> ... Read More
258 Views
You can use STR_TO_DATE() function. Let us first create a table −mysql> create table DemoTable ( AdmissionDate varchar(200) ); Query OK, 0 rows affected (1.19 sec)Insert records in the table using insert command −mysql> insert into DemoTable values('12-01-2019'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('14-12-2016'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('26-04-2018'); Query OK, 1 row affected (0.34 sec) mysql> insert into DemoTable values('31-05-2013'); Query OK, 1 row affected (0.30 sec)Display all records from the table using select statement −mysql> select * from DemoTable;This will produce the ... Read More
86K+ Views
To create a table with only date column, you can use DATE type. Let us first create a table −mysql> create table DemoTable ( StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, StudentName varchar(20), StudentAdmissionDate DATE ); Query OK, 0 rows affected (0.47 sec)Insert records in the table using INSERT command −mysql> insert into DemoTable(StudentName, StudentAdmissionDate) values('Chris', now()); Query OK, 1 row affected, 1 warning (0.12 sec) mysql> insert into DemoTable(StudentName, StudentAdmissionDate) values('Robert', curdate()); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable(StudentName, StudentAdmissionDate) values('David', '2019-05-21'); Query OK, 1 row affected (0.16 sec)Display all ... Read More
10K+ Views
You can use ORDER BY clause or aggregate function MAX() to select the maximum value.Using ORDER BYFollowing is the syntax −select yourColumnName from yourTableName order by yourColumnName desc limit 0, 1;Let us first create a table −mysql> create table DemoTable ( Number int ); Query OK, 0 rows affected (0.52 sec)Insert records in the table using insert command −mysql> insert into DemoTable values(790); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values(746); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values(480); Query OK, 1 row affected (0.15 sec) mysql> insert into ... Read More
185 Views
You can use a CASE statement for this. Let us first create a table −mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, Name varchar(20) ); Query OK, 0 rows affected (1.11 sec)Insert records in the table using insert command −mysql> insert into DemoTable(Name) values('John'); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable(Name) values('Carol'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable(Name) values('David'); Query OK, 1 row affected (0.13 sec)Display all records from the table using select statement −mysql> select * from DemoTable;This will produce the following ... Read More
2K+ Views
You can use LPAD() along with rand() and floor() to generate 6-digit random number. Let us first create a table −mysql> create table DemoTable ( Value int ); Query OK, 0 rows affected (0.64 sec)Insert records in the table using insert command −mysql> insert into DemoTable values(1); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values(2); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values(3); Query OK, 1 row affected (0.24 sec) mysql> insert into DemoTable values(4); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values(5); Query OK, ... Read More
2K+ Views
You can use NOW() for this. Following is the syntax −select * from yourTableName where yourColumnName> now();Let us first create a table −mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, expiryDateOfMedicine datetime ); Query OK, 0 rows affected (0.55 sec)Insert records in the table using insert command −mysql> insert into DemoTable(expiryDateOfMedicine) values('2019-04-27 11:29:00'); Query OK, 1 row affected (0.36 sec) mysql> insert into DemoTable(expiryDateOfMedicine) values('2019-04-26 10:39:21'); Query OK, 1 row affected (0.41 sec) mysql> insert into DemoTable(expiryDateOfMedicine) values('2019-04-28 11:30:10'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable(expiryDateOfMedicine) values('2019-04-29 12:44:11'); ... Read More
436 Views
You can use AS command for this. Let us first create a table −mysql> create table DemoTable ( Name varchar(20) ); Query OK, 0 rows affected (0.56 sec)Insert records in the table using insert command −mysql> insert into DemoTable values('John'); Query OK, 1 row affected (0.18 sec)Display all records from the table using select statement −mysql> select * from DemoTable;This will produce the following output −+------+ | Name | +------+ | John | +------+ 1 row in set (0.00 sec)Here is the query to create the second table.mysql> create table DemoTable2 ( Name varchar(20) ... Read More
365 Views
Use NOT LIKE for this. Let us first create a table −mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, StudentFullName varchar(40) ); Query OK, 0 rows affected (0.66 sec)Insert records in the table using insert command −mysql> insert into DemoTable(StudentFullName) values('JohnSmith'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable(StudentFullName) values('John Doe'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable(StudentFullName) values('Adam Smith'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable(StudentFullName) values('CarolTaylor'); Query OK, 1 row affected (0.19 sec)Display all records from the table using ... Read More
141 Views
You need to use GROUP BY for this. Let us first create a table −mysql> create table DemoTable ( StudentFirstName varchar(20) ); Query OK, 0 rows affected (0.74 sec)Insert records in the table using insert command −mysql> insert into DemoTable values('John'); Query OK, 1 row affected (1.34 sec) mysql> insert into DemoTable values('Carol'); Query OK, 1 row affected (0.28 sec) mysql> insert into DemoTable values('John'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('John'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('Bob'); Query OK, 1 row affected (0.25 sec) mysql> ... Read More