- 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
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
318 Views
You can use update command along with a user-defined variable. Let us first create a table −mysql> create table DemoTable ( FirstName varchar(20), Position int ); Query OK, 0 rows affected (0.71 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Chris', 100); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('Robert', 120); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable values('David', 130); Query OK, 1 row affected (0.16 sec)Following is the query to display all records from the table using select statement −mysql> select *from DemoTable;This will produce ... Read More
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
2K+ Views
To convert date YYYYMMDD to YY-MM-DD in MySQL, use the below syntax −select date_format(str_to_date(yourColumnName, '%Y%m%d'), '%Y-%m-%d') from yourTableName;Let us first create a table −mysql> create table DemoTable ( ClientId int NOT NULL AUTO_INCREMENT PRIMARY KEY, ClientProjectDeadline varchar(200) ); Query OK, 0 rows affected (0.57 sec)Insert some records in the table using insert command. We have inserted dates in the YYYYMMDD format −mysql> insert into DemoTable(ClientProjectDeadline) values('20121221'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable(ClientProjectDeadline) values('20190416'); Query OK, 1 row affected (0.53 sec) mysql> insert into DemoTable(ClientProjectDeadline) values('20160624'); Query OK, 1 row affected (0.20 sec) mysql> ... Read More
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
445 Views
You can use IN() to display all records except one in MySQL. Let us first create a table −mysql> create table DemoTable ( Id int, FirstName varchar(20) ); Query OK, 0 rows affected (0.57 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(100, 'Larry'); Query OK, 1 row affected (0.31 sec) mysql> insert into DemoTable values(10, 'Chris'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values(110, 'Robert'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values(90, 'David'); Query OK, 1 row affected (0.20 sec)Following is the query ... Read More
![Krantik Chavan](https://www.tutorialspoint.com/assets/profiles/13545/profile/60_126883-1512724834.jpg)
223 Views
In order to get the greatest of two columns values in MySQL, you need to use GREATEST() function. Following is the syntax:select greatest(yourColumnName1, yourColumnName2) AS anyAliasName from yourTableName; 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.63 sec)Following is the query to insert some records in the table using insert command:mysql> insert into DemoTable(Number1, Number2) values(1000, 10000); Query OK, 1 row affected (0.49 sec) mysql> insert into DemoTable(Number1, Number2) values(600, 900); Query OK, 1 row affected (0.12 sec) mysql> ... Read More
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
65 Views
Let us first create a table with Id as auto_increment −mysql> create table DemoTable ( UserId int NOT NULL AUTO_INCREMENT PRIMARY KEY, UserName varchar(20) ); Query OK, 0 rows affected (0.56 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(UserName) values('John'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable(UserName) values('Larry'); Query OK, 1 row affected (0.35 sec) mysql> insert into DemoTable(UserName) values('Chris'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable(UserName) values('Bob'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable(UserName) values('Carol'); Query OK, 1 row affected ... Read More
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
427 Views
You can use SHOW command for this. Following is the syntax −show columns from yourTableName;Let us first create a table −mysql> create table DemoTable ( StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, StudentFirstName varchar(20), StudentLastName varchar(20), StudentAge int, StudentAddress varchar(200) ); Query OK, 0 rows affected (0.54 sec)Following is the query to get the names of my MySQL table columns −mysql> show columns from DemoTable;This will produce the following output −+------------------+--------------+------+-----+---------+----------------+ | Field | Type | Null ... Read More
![Krantik Chavan](https://www.tutorialspoint.com/assets/profiles/13545/profile/60_126883-1512724834.jpg)
77 Views
You can use ORDER BY IF() to get records in a certain order. Let us first create a table:mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, FirstName varchar(20), Branch varchar(20) ); Query OK, 0 rows affected (1.96 sec)Following is the query to insert some records in the table using insert command:mysql> insert into DemoTable(FirstName, Branch) values('John', 'CS'); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable(FirstName, Branch) values('Carol', 'ME'); Query OK, 1 row affected (0.25 sec) mysql> insert into DemoTable(FirstName, Branch) values('David', 'ME'); Query OK, 1 row affected (0.11 sec) mysql> ... Read More
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
130 Views
You can use TRUNCATE() method to floor the values instead of round. Let us first create a table −mysql> create table DemoTable ( Value DECIMAL(20, 8) ); Query OK, 0 rows affected (0.54 sec)Insert records in the table using insert command −mysql> insert into DemoTable values(23.5654433); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values(12.345542211); Query OK, 1 row affected, 1 warning (0.21 sec) mysql> insert into DemoTable values(12345.678543); Query OK, 1 row affected (0.22 sec)Following is the query to display all records from the table using select statement −mysql> select *from DemoTable;This will produce the ... Read More
![Krantik Chavan](https://www.tutorialspoint.com/assets/profiles/13545/profile/60_126883-1512724834.jpg)
345 Views
To change the file extension in the text column, you can use UPDATE command along with REPLACE() function. Let’s say we have some columns with extensions and we need to replace all of them. For that, let us first create a table with the extension columns set as text type:mysql create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, ProgramExtension1 text, ProgramExtension2 text, ImageExtension text ); Query OK, 0 rows affected (0.52 sec)Following is the query to insert records in the table using insert command:mysql> insert into DemoTable(ProgramExtension1, ProgramExtension2, ImageExtension)values('.java', '.c', '.jpeg'); Query OK, ... Read More
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
348 Views
You can use aggregate function COUNT() from MySQL to count horizontal values on a database. Let us first create a table −mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, FirstValue int, SecondValue int, ThirdValue int, FourthValue int ); Query OK, 0 rows affected (0.59 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(FirstValue, SecondValue, ThirdValue, FourthValue) values(-18, 45, 0, 155); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable(FirstValue, SecondValue, ThirdValue, FourthValue) values(0, 235, null, 15); Query OK, 1 row affected (0.20 sec)Following is the query to display all records from the table using select statement −mysql> select *from DemoTable;This will produce the following ... Read More