- 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)
84 Views
For this, use GROUP_CONCAT(). For only 1 values, work with MySQL WHERE clause. Let us first create a table −mysql> create table DemoTable ( PlayerName varchar(40), PlayerStatus tinyint(1) ); Query OK, 0 rows affected (0.60 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Chris', 1); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('David', 0); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('Sam', 1); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values('Carol', 1); Query OK, 1 row affected (0.12 sec) mysql> insert ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
126 Views
The easiest way to achieve this is by using the MySQL SUBSTRING_INDEX() function. Let us first create a table −mysql> create table DemoTable ( ZipCode varchar(50) ); Query OK, 0 rows affected (2.02 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('52533-909'); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable values('12345-674'); Query OK, 1 row affected (0.27 sec) mysql> insert into DemoTable values('89893-890'); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable values('AAAAA-783'); Query OK, 1 row affected (0.25 sec)Display all records from the table using select statement −mysql> ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
2K+ Views
Use UNION to select from two tables. Let us first create a table −mysql> create table DemoTable1 ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, FirstName varchar(20) ); Query OK, 0 rows affected (0.90 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1(FirstName) values('Chris') ; Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable1(FirstName) values('Adam'); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable1(FirstName) values('Sam'); Query OK, 1 row affected (0.16 sec)Display all records from the table using select statement −mysql> select *from DemoTable1;This will produce the following output −+----+-----------+ ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
412 Views
For the lowest values in a MySQL column, use the MIN() method and for highest, use the MAX() method. Let us first create a table −mysql> create table DemoTable ( CustomerName varchar(20), ProductAmount int ) ; Query OK, 0 rows affected (1.03 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Chris', 3599); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('David', 7843); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('Mike', 97474); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable values('Bob', 65884); Query OK, ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
192 Views
Use MySQL IN() to avoid too many OR statements. Let us first create a table −mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, Name varchar(40) ); Query OK, 0 rows affected (0.89 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(Name) values('Chris'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable(Name) values('Robert'); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable(Name) values('Mike'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable(Name) values('Sam'); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable(Name) values('David'); ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
2K+ Views
To select different values on the basis of condition, use CASE statement. Let us first create a table −mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, Name varchar(40), Score int ) ; Query OK, 0 rows affected (0.54 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(Name, Score) values('Chris', 45); Query OK, 1 row affected (0.24 sec) mysql> insert into DemoTable(Name, Score) values('David', 68); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable(Name, Score) values('Robert', 89); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable(Name, Score) ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
594 Views
To randomly select rows, use ORDER BY RAND() with LIMIT. Use DISTINCT for distinct rows. Let us first see an example and create a table −mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, Name varchar(40) ); Query OK, 0 rows affected (0.54 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(Name) values('John Doe'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable(Name) values('Chris Brown'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable(Name) values('Adam Smith'); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable(Name) ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
3K+ Views
For this, you need to use PreparedStatement in Java for update. Let us first create a table −mysql> create table DemoTable( Id int, FirstName varchar(40) ); Query OK, 0 rows affected (0.62 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(100, 'Chris'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values(111, 'Mike'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values(121, 'Sam'); Query OK, 1 row affected (0.09 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)
102 Views
Such errors arise when you avoid using the DELIMITER concept. Let us see an example and run a query for stored procedure −mysql> DELIMITER // mysql> CREATE PROCEDURE correct_procedure() BEGIN SELECT 'Hello MySQL !!!'; END // Query OK, 0 rows affected (0.12 sec) mysql> DELIMITER ;Following is the syntax to call the stored procedure −call yourStoredProcedureName();Call the stored procedure using CALL command −mysql> call correct_procedure();This will produce the following output −+-----------------+ | Hello MySQL !!! | +-----------------+ | Hello MySQL !!! | +-----------------+ 1 row in set (0.00 sec) Query OK, 0 rows affected (0.02 sec)
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
173 Views
To set new delay time, use INTERVAL and update the column wth SETa clause and UPDATE command. Let us first create a table −mysql> create table DemoTable ( DelayTime time ); Query OK, 0 rows affected (1.21 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('11 :30 :10'); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable values('12 :40 :00'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('05 :45 :24'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values('09 :00 :10'); Query OK, 1 row ... Read More