- 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
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
1K+ Views
To set a flag, you can set the type as tinyint(1) type. Following is the syntax −yourColumnName tinyint(1) DEFAULT 1;Let us first create a table −mysql> create table DemoTable ( ClientId int NOT NULL AUTO_INCREMENT PRIMARY KEY, ClientName varchar(20), isMarried tinyint(1) DEFAULT 1 ); Query OK, 0 rows affected (0.64 sec)Insert some records in the table using insert command −mysql> INSERT INTO DemoTable(ClientName, isMarried) values('Larry', 0); Query OK, 1 row affected (0.16 sec) mysql> INSERT INTO DemoTable(ClientName) values('David'); Query OK, 1 row affected (0.12 sec) mysql> INSERT INTO DemoTable(ClientName, isMarried) values('Mike', 1); Query OK, 1 row affected (0.19 ... Read More
![Krantik Chavan](https://www.tutorialspoint.com/assets/profiles/13545/profile/60_126883-1512724834.jpg)
2K+ Views
You can use ORDER BY SUBSTRING() to order by certain part of a string in MySQL. Let us first create a table:mysql> create table DemoTable (UserId varchar(200)); Query OK, 0 rows affected (0.68 sec)Following is the query to insert records in the table using insert command:mysql> insert into DemoTable values('USER_1234'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('USER_John'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values('USER_Sam'); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable values('USER_Carol'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values('USER_Bob'); Query OK, ... Read More
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
319 Views
You can use AS command for alias to show tables in MySQL result. Following is the syntax −SELECT TABLE_NAME AS anyAliasName FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = DATABASE();Let us implement the above syntax −mysql> SELECT TABLE_NAME AS MY_TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = DATABASE();This will produce the following output −+------------------------------------+ | MY_TABLE_NAME | +------------------------------------+ | a | | accumulateddemo | | add10minutedemo ... Read More
![Krantik Chavan](https://www.tutorialspoint.com/assets/profiles/13545/profile/60_126883-1512724834.jpg)
432 Views
Following is the syntax to GROUP BY in a select query on positive or negative values:select *from yourTableName group by -yourColumnName;Let us first create a table:mysql> create table DemoTable (Value int); Query OK, 0 rows affected (0.60 sec)Following is the query to insert some records in the table using insert command:mysql> insert into DemoTable values(-10); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable values(-20); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values(20); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values(10); Query OK, 1 row affected (0.13 sec) mysql> insert ... Read More
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
514 Views
Let us first create a table. Here, we have two columns with varchar type −mysql> create table DemoTable ( UserId int NOT NULL AUTO_INCREMENT PRIMARY KEY, UserFirstName varchar(10), UserLastName varchar(20) , UserAge int ); Query OK, 0 rows affected (0.96 sec)Let us check the description of table using DESC command −mysql> desc DemoTable;This will produce the following output −+---------------+-------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +---------------+-------------+------+-----+---------+----------------+ | UserId | int(11) | NO ... Read More
![Daniol Thomas](https://www.tutorialspoint.com/assets/profiles/13551/profile/60_130035-1512726078.jpg)
2K+ Views
To set a variable in MySQL, you need to use the SET command. Following is the syntax:set @yourVariableName:=yourValue; select *from yourTableName where yourColumnName=@yourVariableName;Let us first create a table:mysql> create table DemoTable ( Id int, FirstName varchar(20), LastName varchar(20) ); Query OK, 0 rows affected (0.83 sec)Following is the query to insert some records in the table using insert command:mysql> insert into DemoTable values(10, 'Carol', 'Taylor'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values(20, 'John', 'Doe'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values(30, 'John', 'Smith'); Query OK, 1 row ... Read More
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
276 Views
Use LPAD() to add 0's to numbers with less than 9 digits. Let us first create a table −mysql> create table DemoTable ( Value varchar(20) ); Query OK, 0 rows affected (0.55 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('3646465'); Query OK, 1 row affected (0.29 sec) mysql> insert into DemoTable values('9485757591'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values('485756'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values('959585'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('124'); Query OK, 1 row affected ... Read More
![Daniol Thomas](https://www.tutorialspoint.com/assets/profiles/13551/profile/60_130035-1512726078.jpg)
885 Views
To alter row_format to dynamic in MySQL, following is the syntax:ALTER TABLE yourTableName ROW_FORMAT=DYNAMIC;Let us first create a table:mysql> create table DemoTable ( CustomerId int NOT NULL AUTO_INCREMENT PRIMARY KEY, CustomerName varchar(200), CustomerAge int, CustomerAddress varchar(200) ); Query OK, 0 rows affected (0.73 sec)Let us check the description of table using DESC command:mysql> desc DemoTable;This will produce the following output:+-----------------+--------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra ... Read More
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
209 Views
Here, we will use OCTET_LENGTH to check the length of a record since we want the records with length more than 1. Let us first create a table −mysql> create table DemoTable ( UserId int NOT NULL AUTO_INCREMENT PRIMARY KEY, UserName varchar(20), UserGender varchar(20) ); Query OK, 0 rows affected (0.55 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(UserName, UserGender) values('John', 'M'); Query OK, 1 row affected (0.82 sec) mysql> insert into DemoTable(UserName, UserGender) values('Carol', 'Male'); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable(UserName, UserGender) values('Mia', 'Female'); Query OK, ... Read More
![Daniol Thomas](https://www.tutorialspoint.com/assets/profiles/13551/profile/60_130035-1512726078.jpg)
677 Views
To delete record with the lowest id, you can use the following syntax:delete from yourTableName order by yourColumnName limit 1;Let us first create a table:mysql> create table DemoTable ( Id int, Name varchar(20) ); Query OK, 0 rows affected (0.75 sec)Following is the query to insert records in the table using insert command:mysql> insert into DemoTable values(10, 'Larry'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values(100, 'Mike'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values(30, 'Sam'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values(90, 'Chris'); Query ... Read More