- 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)
6K+ Views
Yes, we can do that. Let us first create a table −mysql> create table DemoTable ( Name varchar(50) ); Query OK, 0 rows affected (0.63 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('John'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('Adam'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values('Bob'); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable values('Mike'); Query OK, 1 row affected (0.16 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)
447 Views
For this, use RAND() for random records and LIMIT 1 to get only a single value. However, use the WHERE clause to select that particular ‘Name’, which is repeating.Let us first create a table −mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, Name varchar(20) ); Query OK, 0 rows affected (1.65 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(Name) values('Chris'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable(Name) values('Bob'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable(Name) values('David'); Query OK, 1 row affected ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
84 Views
Let us first create a table −mysql> create table DemoTable ( Name varchar(50), Score int ); Query OK, 0 rows affected (1.02 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Sam', 45); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable values('Mike', 28); Query OK, 1 row affected (0.36 sec) mysql> insert into DemoTable values('Carol', 27); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('David', 67); Query OK, 1 row affected (0.19 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce the ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
192 Views
For this, you can use the BETWEEN keyword. Let us first create a table −mysql> create table DemoTable ( ArrivalDate date ); Query OK, 0 rows affected (0.93 sec)Let’s say the current date is 2019-08-31.Insert some records in the table using insert command −mysql> insert into DemoTable values('2019-04-21'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('2019-03-01'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values('2019-09-01'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values('2019-08-31'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('2019-06-30'); Query OK, 1 ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
456 Views
For this, you need to set sql_mode to 'STRICT_TRANS_TABLES’. This mode issues a warning when an invalid value is inserted but inserts the same value. Let us first create a table −mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, Name varchar(50), Gender char(1) NULL ); Query OK, 0 rows affected (0.99 sec)Insert some records in the table using insert command −mysql> set sql_mode = 'STRICT_TRANS_TABLES'; Query OK, 0 rows affected, 1 warning (0.00 sec) mysql> insert into DemoTable(Name, Gender) select 'Chris', NULL ; Query OK, 1 row affected (0.21 sec) Records: 1 Duplicates: ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
778 Views
For this, you can use ORDER BY IF(). Let us first create a table −mysql> create table DemoTable ( Name varchar(50), Score int ); Query OK, 0 rows affected (0.72 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Chris', 98); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values('David', 45); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('Bob', 56); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('Sam', 89); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('Carol', 78); Query ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
328 Views
Let us first create a table −mysql> create table DemoTable1 ( Id int ); Query OK, 0 rows affected (1.26 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1 values(100); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable1 values(110); Query OK, 1 row affected (0.49 sec) mysql> insert into DemoTable1 values(4); Query OK, 1 row affected (0.44 sec) mysql> insert into DemoTable1 values(3); 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 −+------+ | Id | ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
694 Views
For this, use aggregate function MAX() along with the GROUP BY clause. Let us first create a table −mysql> create table DemoTable ( Id int, Value1 int, Value2 int, Value3 int, Value4 int ); Query OK, 0 rows affected (0.61 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(Id, Value4) values(100, 30); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable(Id, Value1, Value2, Value3) values(100, 20, 60, 40); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable(Id, Value2, Value3, Value4) values(100, 90, 100, 110); Query OK, 1 ... Read More
MySQL query to fetch records with arrangement in the form of numbers and letter like 99S, 50K, etc.?
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
143 Views
The easiest way to achieve this is by using REGEXP. Let us first create a table −mysql> create table DemoTable ( Id varchar(50) ); Query OK, 0 rows affected (0.77 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('John123'); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable values('123Chris'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('99Bob'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('19David'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('99S'); Query OK, 1 row affected (0.18 sec) ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
123 Views
Let us first create a table −mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, Name varchar(50) ); Query OK, 0 rows affected (0.62 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(Name) values('Chris'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable(Name) values('Robert'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable(Name) values('Chris'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable(Name) values('David'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable(Name) values('Mike'); Query OK, 1 row affected (0.13 sec)Display all records ... Read More