- 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 6702 Articles for Database
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
731 Views
You can use INFORMATION_SCHEMA.COLUMNS table to display MySQL table name with columns. The syntax is as follows −SELECT DISTINCT TABLE_NAME, Column_Name FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = 'yourDatabaseName';Here, we have a database with the name ‘sample’ with tables. The query is as follows to display table name along with column name −mysql> SELECT DISTINCT TABLE_NAME, Column_Name -> FROM INFORMATION_SCHEMA.COLUMNS -> WHERE TABLE_SCHEMA = 'sample';Output+--------------------------------+-------------------------------+ | TABLE_NAME | COLUMN_NAME | +--------------------------------+-------------------------------+ | aggregatefunctiondemo | UserId ... Read More
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
2K+ Views
Achieve this with the help of where clause.The syntax is as followsSELECT yourColumnName1, yourColumnName2, ...N FROM yourTableName WHERE ( SELECT COUNT(*) FROM yourTableName )=2;To understand the concept, let us create a table. The query to create a table is as followsmysql> create table CountWithSubqueryDemo - > ( - > Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, - > EmployeeName varchar(20) - > ); Query OK, 0 rows affected (2.09 sec)Insert some records in the table using insert command.The query is as followsmysql> insert into CountWithSubqueryDemo(EmployeeName) values('John'); Query OK, 1 row affected (0.54 sec) mysql> ... Read More
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
887 Views
You need to use substring_index() function from MySQL to select text.The syntax is as followsSELECT substring_index(yourColumnName, '/', -1) AS anyAliasName FROM yourTableName;To understand the above concept, let us create a table. The query to create a table is as followsmysql> create table selectTextAfterLastSlashDemo - > ( - > UserId int NOT NULL AUTO_INCREMENT PRIMARY KEY, - > UserPathDirectory varchar(200) - > ); Query OK, 0 rows affected (0.54 sec)Insert some records in the table using insert command.The query is as followsmysql> insert into selectTextAfterLastSlashDemo(UserPathDirectory) values('C:/MyFolder1/MyEntityFramework'); Query OK, 1 ... Read More
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
1K+ Views
The best way to change the date format in MySQL SELECT is as followsSELECT DATE_FORMAT(yourColumnName, "%d/%m/%Y %H:%i") AS anyAliasName FROM yourTableName WHERE yourCondition;To understand the above concept, let us create a table. The query to create a table is as followsmysql> create table bestDateFormatDemo - > ( - > Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, - > ArrivalDateTime datetime - > ); Query OK, 0 rows affected (0.64 sec)Insert some records in the table using insert command.The query is as followsmysql> insert into bestDateFormatDemo(ArrivalDateTime) values(now()); Query OK, ... Read More
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
87 Views
Yes, you can get expanded out in MySQL using the /G, instead of semicolon(;). The syntax is as followsSELECT *FROM yourTableName\GLet us first create a table as an examplemysql> create table expandedOutputDemo - > ( - > EmployeeId int NOT NULL AUTO_INCREMENT PRIMARY KEY, - > EmployeeName varchar(20), - > EmployeeAge int - > ); Query OK, 0 rows affected (0.66 sec)Insert some records in the table using insert command.The query is as followsmysql> insert into expandedOutputDemo(EmployeeName, EmployeeAge) values('Larry', 27); Query OK, 1 row affected (0.16 sec) mysql> insert into expandedOutputDemo(EmployeeName, EmployeeAge) values('Mike', 29); Query ... Read More
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
149 Views
Get the create and update tables exact date using the create_time or update_time in MySQL.At first, use the SHOW command. The syntax is as followsSHOW TABLE STATUS;We are considering our database ‘test3’, which is already having some tablesmysql> use test3; Database changedNow use the following query to display all the tables in the database test3mysql> show tables;The following is the output+-------------------------+ | Tables_in_test3 | +-------------------------+ | add6hour | | deletedemo | | differentdatetime | | fieldlessthan5chars | | ... Read More
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
514 Views
The syntax is as follows to rename Root @localhostUPDATE MySQL.user SET user = ‘yourNewRootName’ WHERE user = 'root';To understand the above concept, let us check all the user names and host. The query is as followsmysql> select user, host from MySQL.user;The following is the output+------------------+-----------+ | user | host | +------------------+-----------+ | Bob | % | | Manish | % | | User2 | % ... Read More
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
107 Views
You can use two approaches to know the version of MySQL. In the first approach, you can use version() to know the MySQL Server version. The first approach is as followsSELECT VERSION();In the second approach, you can use SHOW VARIABLES command to know the MySQL version. The second approach is as followsSHOW VARIABLES WHERE Variable_name = 'version';Let us learn about both the syntaxes one by one.Using version()mysql> select version();The following is te output displaying the current version of the MySQL you are using+-----------+ | version() | +-----------+ | 8.0.12 | +-----------+ 1 row in set (0.00 sec)The ... Read More
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
6K+ Views
You can use UNION to get the previous and next record in MySQL.The syntax is as follows(select *from yourTableName WHERE yourIdColumnName > yourValue ORDER BY yourIdColumnName ASC LIMIT 1) UNION (select *from yourTableName WHERE yourIdColumnName < yourValue ORDER BY yourIdColumnName DESC LIMIT 1);To understand the concept, let us create a table. The query to create a table is as followsmysql> create table previousAndNextRecordDemo - > ( - > Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, - > Name varchar(30) - > ); Query OK, 0 rows affected (1.04 ... Read More
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
1K+ Views
Yes, it is possible to calculate a correlation in a query. To understand the correlation in a query, you need to first create a table. The query to create a table is as followsmysql> create table correlationDemo - > ( - > value float not null, - > value2 float not null - > ); Query OK, 0 rows affected (0.62 sec)Insert some records in the table with the help of insert command. The query is as follows to insert records in the tablemysql> insert into correlationDemo values(1, ... Read More