- 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 4219 Articles for MySQLi
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
825 Views
To prevent duplicate entry, add constraint UNIQUE. Let us first create a table −mysql> create table DemoTable ( Id int, Name varchar(100) ); Query OK, 0 rows affected (0.79 sec)Here is the query to prevent MySQL double insert using UNIQUE −mysql> alter table DemoTable add constraint id_NameUnKey UNIQUE(Id, Name); Query OK, 0 rows affected (0.82 sec) Records: 0 Duplicates: 0 Warnings: 0Insert records in the table using insert command. When we will try to the same record again, then the “Duplicate entry” error will be visible −mysql> insert into DemoTable values(11, 'John'); Query OK, 1 row affected (0.18 ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
2K+ Views
You can use LPAD() from MySQL for this. Let us first create a table −mysql> create table DemoTable ( FullName varchar(100) ); Query OK, 0 rows affected (0.81 sec)Insert records in the table using insert command −mysql> insert into DemoTable values('John Smith'); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable values('David Miller'); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable values('Sam Williams'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values('Carol Taylor'); Query OK, 1 row affected (0.47 sec)Display records from the table using select command −mysql> select *from DemoTable;This ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
852 Views
To select all except the first character in a string, you can use SUBSTR() method. Let us first create a table −mysql> create table DemoTable ( FirstName varchar(20) ); Query OK, 0 rows affected (0.63 sec)Insert records in the table using insert command −mysql> insert into DemoTable values('Larry'); Query OK, 1 row affected (0.24 sec) mysql> insert into DemoTable values('Carol'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('Robert'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('David'); Query OK, 1 row affected (0.14 sec)Display records from the table using select command −mysql> ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
783 Views
You need to use backticks around the table name where the table name has blank space. Let us first create a table. Here, we have used backtick −mysql> create table `Demo Table138` ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, Price int ); Query OK, 0 rows affected (0.47 sec)Insert records in the table using insert command −mysql> insert into `Demo Table138`(Price) values(450); Query OK, 1 row affected (0.18 sec) mysql> insert into `Demo Table138`(Price) values(499); Query OK, 1 row affected (0.16 sec) mysql> insert into `Demo Table138`(Price) values(199); Query OK, 1 row affected (0.17 sec) mysql> insert into ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
191 Views
You can use aggregate function AVG() for this. Let us first create a table −mysql> create table DemoTable ( Value1 int, Value2 int, Value3 int ); Query OK, 0 rows affected (0.54 sec)Insert records in the table using insert command −mysql> insert into DemoTable values(10, 20, 30); Query OK, 1 row affected (0.30 sec) mysql> insert into DemoTable values(13, 15, 18); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values(21, 31, 41); Query OK, 1 row affected (0.21 sec)Display records from the table using select command −mysql> select *from DemoTable;This will produce the following ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
113 Views
You can use ORDER BY clause for this. Let us first create a table −mysql> create table DemoTable ( FirstName varchar(200) ); Query OK, 0 rows affected (0.93 sec)Insert records in the table using insert command −mysql> insert into DemoTable values('Larry'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values('Carol'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable values('Sam'); Query OK, 1 row affected (0.29 sec) mysql> insert into DemoTable values('Mike'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('David'); Query OK, 1 row affected (0.18 sec)Display records from the ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
271 Views
You can use CASE statement with UPDATE command for this. Let us first create a table −mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, Value int ); Query OK, 0 rows affected (1.44 sec)Insert records in the table using insert command −mysql> insert into DemoTable(Value) values(100); Query OK, 1 row affected (0.47 sec) mysql> insert into DemoTable(Value) values(0); Query OK, 1 row affected (4.16 sec) mysql> insert into DemoTable(Value) values(104); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable(Value) values(0); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable(Value) values(5); Query ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
187 Views
To store date in MySQL, use the STR_TO_DATE() method −insert into yourTableName values(STR_TO_DATE('yourDate', '%d/%m/%Y'));Let us first create a table −mysql> create table DemoTable ( AdmissionDate date ); Query OK, 0 rows affected (0.62 sec)Insert records in the table using insert command −mysql> insert into DemoTable values(STR_TO_DATE('10/01/2013', '%d/%m/%Y')); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable values(STR_TO_DATE('31/01/2015', '%d/%m/%Y')); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values(STR_TO_DATE('23/04/2019', '%d/%m/%Y')); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable values(STR_TO_DATE('01/03/2019', '%d/%m/%Y')); Query OK, 1 row affected (0.48 sec)Display records from the table using select ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
437 Views
Let us first create a table. Here, we have set UserId as AUTO_INCREMENT PRIMARY KEY −mysql> create table DemoTable ( UserId int NOT NULL AUTO_INCREMENT PRIMARY KEY ); Query OK, 0 rows affected (0.72 sec)Following is the query to set int column to auto increment by 1 beginning at 10000 −mysql> alter table DemoTable AUTO_INCREMENT=10000; Query OK, 0 rows affected (0.31 sec) Records: 0 Duplicates: 0 Warnings: 0Insert records in the table using insert command −mysql> insert into DemoTable values(); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values(); Query OK, 1 row affected (0.19 sec) ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
2K+ Views
To order by from highest to lowest value, you can use ORDER BY DESC command −select *from yourTableName order by yourColumnName DESC;If you want the result from lowest to highest, you can use ORDER BY ASC command −select *from yourTableName order by yourColumnName ASC;Let us first create a table −mysql> create table DemoTable ( Value int ); Query OK, 0 rows affected (0.56 sec)Insert records in the table using insert command −mysql> insert into DemoTable values(134); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable values(245); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable ... Read More