- 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)
114 Views
To get at least x number of rows, you need to use the LIMIT clause. Following is the syntax −select *from yourTableName order by yourColumnName DESC limit yourXNumberOfRows;Let us first create a table −mysql> create table DemoTable ( EmployeeId int NOT NULL AUTO_INCREMENT PRIMARY KEY, EmployeeName varchar(100) ); Query OK, 0 rows affected (0.76 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(EmployeeName) values('Chris'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable(EmployeeName) values('David'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable(EmployeeName) values('Bob'); Query OK, 1 row affected (0.51 sec) ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
793 Views
The MySQL CASE statement is faster in comparison to PHP if statement. The PHP if statement takes too much time because it loads data and then process while CASE statement does not.Let us first create a table and work around an example of MySQL CASE statement −mysql> create table DemoTable (Value int); Query OK, 0 rows affected (0.70 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(100); Query OK, 1 row affected (0.24 sec) mysql> insert into DemoTable values(500); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values(1000); Query OK, 1 row ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
230 Views
For this, you can use INTERVAL 12 hour using DATE_ADD(). Let us first create a table −mysql> create table DemoTable (DueDateTime datetime); Query OK, 0 rows affected (0.60 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('2019-07-12 10:50:30'); Query OK, 1 row affected (0.29 sec) mysql> insert into DemoTable values('2019-07-12 22:02:00'); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable values('2019-07-12 11:12:10'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values('2019-07-12 09:02:00'); Query OK, 1 row affected (0.10 sec)Display all records from the table using select statement −mysql> select *from ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
250 Views
To generate random numbers, use the ORDER BY RAND() function in MySQL. Let us first create a table −mysql> create table DemoTable (Value int); Query OK, 0 rows affected (0.76 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(89); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values(98); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values(10); Query OK, 1 row affected (0.34 sec) mysql> insert into DemoTable values(78); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values(75); Query OK, 1 row affected (0.14 sec) mysql> ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
206 Views
For this, you can use LAST_INSERT_ID(). Let us first create a table. Here, we have set the auto_increment id to StudentId column −mysql> create table DemoTable1 (StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY); Query OK, 0 rows affected (0.58 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1 values(null); Query OK, 1 row affected (0.18 sec)Display all records from the table using select statement −mysql> select *from DemoTable1;This will produce the following output −+-----------+ | StudentId | +-----------+ | 1 | +-----------+ 1 row in set (0.00 sec)Following is the query to ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
240 Views
No, MySQL sleep function is not busy-wait. Let us first create a table and implement the SLEEP() function −mysql> create table DemoTable(FirstName varchar(100)); Query OK, 0 rows affected (0.57 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('John'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('Adam'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('Bob'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values('Chris'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('Robert'); Query OK, 1 row affected (0.16 sec)Display all records ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
707 Views
To order by field, use CASE statement. Let us first create a table −mysql> create table DemoTable(StudentId varchar(100)); Query OK, 0 rows affected (1.69 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('STU-980'); Query OK, 1 row affected (0.28 sec) mysql> insert into DemoTable values('STU-1029'); Query OK, 1 row affected (0.29 sec) mysql> insert into DemoTable values('STU-189'); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable values('STU-890'); Query OK, 1 row affected (0.38 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce the following output −+-----------+ | ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
743 Views
For this, use count(*) and the divide the count of two different sets of rows. Let us first create a table −mysql> create table DemoTable(isMarried tinyint(1)); Query OK, 0 rows affected (0.53 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(1); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable values(0); Query OK, 1 row affected (0.26 sec) mysql> insert into DemoTable values(1); Query OK, 1 row affected (0.07 sec) mysql> insert into DemoTable values(1); Query OK, 1 row affected (0.26 sec) mysql> insert into DemoTable values(1); Query OK, 1 row affected (0.17 ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
636 Views
To copy all rows of a table to another table, use the below syntax −insert into yourTableName2(yourColumnName1, ...N) select yourColumnName1, ..N from yourTableName1;Let us first create a table −mysql> create table DemoTable1(FirstName varchar(100)); Query OK, 0 rows affected (1.11 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1 values('John'); Query OK, 1 row affected (0.31 sec) mysql> insert into DemoTable1 values('Chris'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1 values('Bob'); Query OK, 1 row affected (0.40 sec)Display all records from the table using select statement −mysql> select *from DemoTable1;This will produce the following ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
374 Views
Let’s say we have two tables and both of them have two columns PlayerId and PlayerScore. We need to add the PlayerScore from both these tables, but only for a particular PlayerId.For this, you can use UNION. Let us first create a table −mysql> create table DemoTable1(PlayerId int, PlayerScore int); Query OK, 0 rows affected (9.84 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1 values(1000, 87); Query OK, 1 row affected (3.12 sec) mysql> insert into DemoTable1 values(1000, 65); Query OK, 1 row affected (1.29 sec) mysql> insert into DemoTable1 values(1001, 10); Query OK, 1 ... Read More