- 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)
66 Views
For this, you can use COUNT() along with GROUP BY MONTH(). To match with the current date, use CURRENT_DATE(). The current date is as follows −mysql> select curdate() ; +------------+ | curdate() | +------------+ | 2019-11-30 | +------------+ 1 row in set (0.00 sec)Let us first create a table −mysql> create table DemoTable1819 ( Name varchar(20), RegisteringDate datetime ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1819 values('Chris', '2019-11-29 12:30:34'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1819 ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
266 Views
To count the same value of each row, use COUNT(*) along with GROUP BY clause. Let us first create a table −mysql> create table DemoTable1818 ( Id int, Name varchar(20) ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1818 values(10, 'Chris'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1818 values(11, 'Chris'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1818 values(11, 'Chris'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1818 values(12, 'Chris'); Query ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
936 Views
To pass multiple ids to single parameter, use FIND_IN_SET(). Let us first create a table −mysql> create table DemoTable1817 ( EmployeeName varchar(20), CountryName varchar(20) ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1817 values('Chris', 'AUS'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1817 values('David', 'UK'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1817 values('Bob', 'US'); Query OK, 1 row affected (0.00 sec)Display all records from the table using select statement −mysql> select * from DemoTable1817;This ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
392 Views
Following is the syntax to match date with date() function and updating a column −update yourTableName set yourColumnName=yourValue where date(yourColumnName)=curdate();Let us first create a table −mysql> create table DemoTable1816 ( Name varchar(20), JoiningDate datetime ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1816 values('Chris', '2019-11-29 12:34:50'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1816 values('David', '2019-11-30 11:00:00'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1816 values('Mike', '2018-11-30 10:20:30'); Query OK, 1 row affected (0.00 sec)Display ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
274 Views
To randomly select, use ORDER BY RAND(). To select only 2 values, use LIMIT 2 in MySQL. Let us first create a table −mysql> create table DemoTable1815 ( Question text ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1815 values('What is your name?'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1815 values('What is your college name?'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1815 values('What is your nick name?'); Query OK, 1 row affected (0.00 sec) mysql> ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
408 Views
To implement DOUBLE in MySQL, the syntax is as follows −create table yourTableName ( yourColumnName double(5, 2) unsigned );Let us first create a table −mysql> create table DemoTable1814 ( Amount double(5, 2) unsigned ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1814 values(1.98); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1814 values(100.24); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1814 values(198.50); Query OK, 1 row affected (0.00 sec)Display all records from the table ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
1K+ Views
For this, you can use GRANT SELECT statement as in the below syntax −GRANT SELECT ON *.* TO 'yourUserName'@'yourHostName';First list all the user names along with host −mysql> select user, host from mysql.user;This will produce the following output −+------------------+-----------+ | user | host | +------------------+-----------+ | Bob | % | | Charlie | % | | Robert | % | | User2 ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
272 Views
To implement if-else, the syntax is as follows −if yourCondition then yourStatement1; else yourStatement2; end if ;To understand the above concept for if-else in a stored procedure, let us create a stored procedure −mysql> delimiter // mysql> create procedure If_else_stored_demo(value int) begin if value > 1000 then select "your value is greater than 1000"; else select "your value is less than or equal to 1000"; end if ; end // Query OK, 0 rows affected (0.00 ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
2K+ Views
For this, use UNION ALL. Let us first create a table −mysql> create table DemoTable1813 ( Name1 varchar(20), Name2 varchar(20) ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1813 values('John', 'Chris'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1813 values('Adam', 'Robert'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1813 values('Mike', 'Sam'); Query OK, 1 row affected (0.00 sec)Display all records from the table using select statement −mysql> select * from DemoTable1813;This will produce the following ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
409 Views
To extract column name and type, use INFORMATION_SCHEMA.COLUMNS −select concat(column_name, '=', data_type) as anyAliasName from information_schema.columns where table_schema= yourDatabaseName and table_name= yourTableName;Let us first create a table −mysql> create table DemoTable1812 ( Id int, FirstName varchar(20), Age int, isMarried boolean, status ENUM('ACTIVE', 'INACTIVE') ); Query OK, 0 rows affected (0.00 sec)Here is the query to extract column name and type from MySQL:mysql> select concat(column_name, '=', data_type) as COLUMNNAMEANDTYPE from information_schema.columns where table_schema= 'web' and table_name= 'DemoTable1812';This will produce the following output −+-------------------+ | COLUMNNAMEANDTYPE ... Read More