- 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
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
541 Views
We can use the HAVING clause rather than the WHERE in MySQL. Let us first create a table −mysql> create table DemoTable ( Name varchar(50), Price int ); Query OK, 0 rows affected (0.79 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Chris', 30); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('David', 40); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values('Chris', 10); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('Mike', 44); Query OK, 1 row affected (0.14 sec) mysql> insert into ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
173 Views
To display a single random row, use the RAND() with LIMIT. Here, LIMIT is used to fetch the number of records, since we want only a single row, therefore use LIMIT 1. Let us first create a table −mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, Name varchar(50), Quote text ); Query OK, 0 rows affected (0.71 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(Name, Quote) values('Chris', 'MySQL is a relational database'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable(Name, Quote) values('Robert', 'Java is an ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
173 Views
Let us first create a table −mysql> create table DemoTable ( AdmissionDate date ); Query OK, 0 rows affected (0.73 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('2019-08-31'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values('2019-09-01'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('2019-05-10'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values('2019-06-12'); Query OK, 1 row affected (0.25 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce the following output −+---------------+ | AdmissionDate | +---------------+ ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
173 Views
To set a custom value for NULL values, use the UPDATE command along with IS NULL property in a stored procedure. Let us first create a table −mysql> create table DemoTable ( Id int, FirstName varchar(50) ); Query OK, 0 rows affected (0.67 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(100, 'Chris'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values(101, NULL); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable values(102, 'Mike'); Query OK, 1 row affected (0.38 sec) mysql> insert into DemoTable values(103, NULL); Query ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
687 Views
The autoincrement in MySQL gives a unique number every time. By default, it starts at 1. If you want to start from another number, then you need to change the auto-increment value with the help of ALTER command or you can give value at the time of table creation.Let us first create a table −mysql> create table DemoTable ( UniqueNumber int NOT NULL AUTO_INCREMENT, PRIMARY KEY(UniqueNumber) ); Query OK, 0 rows affected (0.53 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(); Query OK, 1 row affected (0.30 sec) mysql> insert into DemoTable ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
63 Views
Let us first create a table −mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, FileID int ) AUTO_INCREMENT=100; Query OK, 0 rows affected (1.36 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(FileID) values(50); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable(FileID) values(60); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable(FileID) values(50); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable(FileID) values(70); Query OK, 1 row affected (0.25 sec) mysql> insert into DemoTable(FileID) values(60); Query OK, 1 row affected (0.28 sec) mysql> ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
200 Views
Let us first create a table −mysql> create table DemoTable ( StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, StudentName varchar(50), StudentAge int ); Query OK, 0 rows affected (0.72 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(StudentName, StudentAge) values('Chris', 21); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable(StudentName, StudentAge) values('David', 23); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable(StudentName, StudentAge) values('Bob', 22); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable(StudentName, StudentAge) values('Carol', 21); Query OK, 1 row affected (0.30 sec)Display all records from ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
636 Views
For this, you can use COUNT() along with DISTINCT. The COUNT() method is to count the records. However, the DISTINCT returns distinct records, whereas COUNT() method counts those unique records. Let us first create a table −mysql> create table DemoTable ( PhoneNumber bigint ); Query OK, 0 rows affected (1.29 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(8567789898); Query OK, 1 row affected (0.94 sec) mysql> insert into DemoTable values(8567789898); Query OK, 1 row affected (0.34 sec) mysql> insert into DemoTable values(9876564534); Query OK, 1 row affected (0.43 sec) mysql> insert into DemoTable ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
116 Views
To order, use the ORDER BY DESC clause. With that, since we want a single ID, which should be the highest, use LIMIT 1. This will fetch the row with highest ID. Let us first create a table −mysql> create table DemoTable ( Id int, FirstName varchar(50) ); Query OK, 0 rows affected (0.83 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(100, 'Chris'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable values(110, 'Robert'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values(120, 'Mike'); Query OK, 1 ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
116 Views
As stated in the official docs −KEY is normally a synonym for INDEX. The key attribute PRIMARY KEY can also be specified as just KEY when given in a column definition. This was implemented for compatibility with other database systems.Let us first create a table −mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, Name varchar(50), Age int ); Query OK, 0 rows affected (0.69 sec)Following is the query for INDEX, which is a synonym to KEY −mysql> create index Name_Age_Index on DemoTable(Name, Age); Query OK, 0 rows affected (0.65 sec) Records: 0 Duplicates: ... Read More