- 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
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
788 Views
Let us first create a table wherein we have a Primary Key CustomerId −mysql> create table DemoTable ( CustomerId int NOT NULL AUTO_INCREMENT, CustomerName varchar(20), CustomerAge int, CustomerCountryName varchar(100), PRIMARY KEY(CustomerId) ); Query OK, 0 rows affected (0.94 sec)Following is the query to get the primary key “column name” of a specific table in MySQL −mysql> SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE WHERE TABLE_NAME = 'DemoTable' AND CONSTRAINT_NAME = 'PRIMARY';This will produce the following output −+-------------+ | COLUMN_NAME | +-------------+ | CustomerId | +-------------+ 1 row in set, 2 warnings (0.12 sec)
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
307 Views
To convert MM/DD/YY to UNIX timestamp, you can use the below syntax −select UNIX_TIMESTAMP(str_to_date(yourColumnName, '%m/%d/%Y')) from yourTableName;Let us first create a table −mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, dateConvertToUnix varchar(100) ); Query OK, 0 rows affected (0.58 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(dateConvertToUnix) values('01/10/2001'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable(dateConvertToUnix) values('03/31/2010'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable(dateConvertToUnix) values('12/31/2016'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable(dateConvertToUnix) values('04/27/2019'); Query OK, 1 ... Read More
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
174 Views
You can use substring() for fields in MySQL to get part of string. Following is the syntax −select substring(yourColumnName, yourStartingIndex, yourEndingIndex) from yourTableName;Let us first create a table −mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, Title longtext ); Query OK, 0 rows affected (0.57 sec)Insert records in the table using insert command −mysql> insert into DemoTable(Title) values('MySQL is a relational database management system'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable(Title) values('MongoDB is a popular No SQL database'); Query OK, 1 row affected (0.18 sec)Display all records from ... Read More
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
265 Views
You cannot use ‘from’ as column name directly because ‘from’ is a reserved word in MySQL.If you want to still use it, then you need to use the backtick symbol.Let us first create a table −mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, `from` varchar(100), Name varchar(10) ); Query OK, 0 rows affected (0.92 sec)Insert records in the table using insert command −mysql> insert into DemoTable(`from`, Name) values('US', 'John'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable(`from`, Name) values('UK', 'Carol'); Query OK, 1 row affected (0.14 sec) mysql> ... Read More
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
1K+ Views
First, you need to know how many columns are present in a table. Following is the syntax to know the column names −show columns from yourTableName;Following is the syntax to concatenate all columns −select concat(yourColumnName1, yourColumnName2, yourColumnName3, ........N) from yourTableName;Let us first create a table −mysql> create table DemoTable ( CustomerId int, CustomerName varchar(20), CustomerAge int ); Query OK, 0 rows affected (0.66 sec)Following is the query to know the exact column −mysql> show columns from DemoTable;This will produce the following output −+--------------+-------------+------+-----+---------+-------+ | Field | Type | Null ... Read More
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
1K+ Views
You can use aggregate function MAX() and MIN() for this.Let us first create a table −mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, Number1 int, Number2 int ); Query OK, 0 rows affected (0.89 sec)Insert records in the table using insert command −mysql> insert into DemoTable(Number1, Number2) values(67, 45); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable(Number1, Number2) values(90, 40); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable(Number1, Number2) values(80, 43); Query OK, 1 row affected (0.48 sec)Display all records from the table using select ... Read More
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
131 Views
To modify an existing column’s data type, you can use MODIFY. Let us first create a table −mysql> create table DemoTable ( ClientId varchar(100), ClientName varchar(100), ClientAge int, ClientProjectDeadline timestamp, ClientCountryName varchar(100), isMarried boolean, ClientNumber bigint ); Query OK, 0 rows affected (0.70 sec)Check the description of table −mysql> desc DemoTable;This will produce the following output −+-----------------------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-----------------------+--------------+------+-----+---------+-------+ | ClientId ... Read More
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
91 Views
You can use UPDATE with DATE_ADD() to update all dates. Let us first create a table −mysql> create table DemoTable ( ClientId int NOT NULL AUTO_INCREMENT PRIMARY KEY, ClientProjectDueDate date ); Query OK, 0 rows affected (1.19 sec)Insert records in the table using insert command −mysql> insert into DemoTable(ClientProjectDueDate) values('2018-01-21'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable(ClientProjectDueDate) values('2019-03-25'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable(ClientProjectDueDate) values('2013-11-01'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable(ClientProjectDueDate) values('2015-06-14'); Query OK, 1 row affected (0.23 sec)Display all records from ... Read More
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
111 Views
You can use a CASE statement for this. Let us first create a table −mysql> create table DemoTable ( Number int ); Query OK, 0 rows affected (0.71 sec)Insert records in the table using insert command −mysql> insert into DemoTable values(490); Query OK, 1 row affected (0.35 sec) mysql> insert into DemoTable values(310); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values(540); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values(123); Query OK, 1 row affected (0.60 sec) mysql> insert into DemoTable values(1230); Query OK, 1 row affected (0.15 sec) mysql> ... Read More
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
837 Views
You can use COUNT(*) along with GROUP BY for this. Let us first create a table −mysql> create table DemoTable ( StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, StudentAge int ); Query OK, 0 rows affected (0.59 sec)Insert records in the table using insert command −mysql> insert into DemoTable(StudentAge) values(16); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable(StudentAge) values(17); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable(StudentAge) values(18); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable(StudentAge) values(17); Query OK, 1 row affected (0.13 sec) mysql> insert into ... Read More