- 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)
8K+ Views
You cannot return table from MySQL function. The function can return string, integer, char etc. To return table from MySQL, use stored procedure, not function.Let us first create a table −mysql> create table DemoTable696 ( Id int, Name varchar(100) ); Query OK, 0 rows affected (0.77 sec)Insert some records in the table using insert command −mysql> insert into DemoTable696 values(100, 'Mike'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable696 values(101, 'Sam'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable696 values(102, 'Adam'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable696 ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
968 Views
The alias name can be used as a variable name in MySQL as shown in the below syntax −select count(*) AS anyAliasName from yourTableName;Let us first create a table −mysql> create table DemoTable695 ( FirstName varchar(100) ); Query OK, 0 rows affected (0.72 sec)Insert some records in the table using insert command −mysql> insert into DemoTable695 values('Chris'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable695 values('Robert'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable695 values('David'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable695 values('Mike'); Query OK, 1 row affected (0.16 ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
17K+ Views
To get the first and last record, use UNION. LIMIT is also used to get the number of records you want.Let us first create a table −mysql> create table DemoTable694 ( EmployeeId int NOT NULL AUTO_INCREMENT PRIMARY KEY, EmployeeName varchar(100), EmployeeSalary int ); Query OK, 0 rows affected (0.58 sec)Insert some records in the table using insert command −mysql> insert into DemoTable694(EmployeeName, EmployeeSalary) values('Chris', 457647); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable694(EmployeeName, EmployeeSalary) values('Robert', 90883); Query OK, 1 row affected (0.25 sec) mysql> insert into DemoTable694(EmployeeName, EmployeeSalary) values('David', 123532); Query OK, 1 row ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
63 Views
Before beginning, let us try to set ‘when’ as column name while using CREATE TABLE statement −mysql> create table DemoTable693( StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, StudentName varchar(100), When datetime );This will produce the following output. An error would be visible:ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'When datetime at line 5You need to wrap the reserved word using backticks, for example, `when`. Let us first create a table and implement the same:mysql> create table ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
81 Views
To get a list of MySQL databases, following is the syntax -show databases;To get the server version, you can use the below syntax -select version();Let us implement the above syntax to get a list of MySQL databases and version -mysql> show databases;This will produce the following output displaying all the databases -+---------------------------+ | Database | +---------------------------+ | bothinnodbandmyisam | | business | | commandline | | customer-tracker | | customer_tracker_database ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
336 Views
When you have identical dates in a table with different time values for each, you can group them easily with GROUP BY DATE.Let us first create a table -mysql> create table DemoTable692 (DueDatetime datetime); Query OK, 0 rows affected (0.97 sec)Insert some records in the table using insert command:mysql> insert into DemoTable692 values('2019-07-21 10:20:00'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable692 values('2019-06-11 11:00:10'); Query OK, 1 row affected (0.24 sec) mysql> insert into DemoTable692 values('2019-07-21 11:00:10'); Query OK, 1 row affected (1.97 sec) mysql> insert into DemoTable692 values('2019-07-21 12:10:10'); Query OK, 1 row affected (0.18 sec)Display ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
159 Views
For descending order result, use DESC. However, LIMIT is used to get fixed number of records −select *from yourTableName order by yourColumnName DESC LIMIT yourLimitNumber;Let us first create a table −mysql> create table DemoTable (Id int, Name varchar(100)); Query OK, 0 rows affected (0.73 sec)ExampleInsert some records in the table using insert command −mysql> insert into DemoTable values(100, 'John'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values(101, 'Chris'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values(102, 'Robert'); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable values(103, 'Bob'); Query OK, ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
82 Views
Let us first create a table −mysql> create table DemoTable (DueDate date); Query OK, 0 rows affected (0.92 sec)ExampleInsert some records in the table using insert command −mysql> insert into DemoTable values('2019-01-12'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('2019-04-01'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values('2019-07-19'); Query OK, 1 row affected (0.15 sec)Display all records from the table using select statement −mysql> select *from DemoTable;Output+------------+ | DueDate | +------------+ | 2019-01-12 | | 2019-04-01 | | 2019-07-19 | +------------+ 3 rows in set (0.00 sec)Following is the query to ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
108 Views
For this, you can use SUBSTRING_INDEX(). Let us first create a table −mysql> create table DemoTable (Number varchar(100)); Query OK, 0 rows affected (0.60 sec)ExampleInsert some records in the table using insert command −mysql> insert into DemoTable values('235678'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable values('1634990'); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable values('678590'); Query OK, 1 row affected (0.46 sec) mysql> insert into DemoTable values('908765432'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('222343388773'); Query OK, 1 row affected (0.35 sec) mysql> insert into DemoTable values('09028215'); Query OK, ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
1K+ Views
For this, use GROUP BY and HAVING. Let us first create a table −mysql> create table DemoTable ( StudentName varchar(100), DueDate date ); Query OK, 0 rows affected (0.72 sec)ExampleInsert some records in the table using insert command −mysql> insert into DemoTable values('John', '2019-01-11'); Query OK, 1 row affected (0.26 sec) mysql> insert into DemoTable values('Chris', '2019-02-11'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable values('Chris', '2019-03-11'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values('John', '2019-04-11'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('Bob', '2019-05-11'); ... Read More