- 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)
367 Views
The coalesce() can be used to print first NOT NULL column value. Let us first create a table −mysql> create table DemoTable1927 ( StudentName varchar(20), StudentSubject varchar(20) ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1927 values('Chris', 'MySQL'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1927 values('David', NULL); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1927 values(NULL, 'MongoDB'); Query OK, 1 row affected (0.00 sec)Display all records from the table using select statement −mysql> select * from DemoTable1927;This will ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
53 Views
For this, you can use ORDER BY CASE statement. Let us create a table −mysql> create table DemoTable1926 ( Position varchar(20), Number int ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1926 values('Highest', 50); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1926 values('Highest', 30); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1926 values('Lowest', 100); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1926 values('Lowest', 120); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1926 values('Lowest', ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
87 Views
For this, use UPDATE command along with CASE statement. Let us first create a table −mysql> create table DemoTable1925 ( StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, StudentName varchar(20), StudentMarks int ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1925(StudentName, StudentMarks) values('Chris', 98); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1925(StudentName, StudentMarks) values('David', 45); Query OK, 1 row affected (0.00 sec)Display all records from the table using select statement −mysql> select * from DemoTable1925;This will produce the following output −+-----------+-------------+--------------+ | ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
85 Views
To update records with a specific year, use the YEAR() method as in the below syntax:update yourTableName set yourColumnName1=yourValue1 where YEAR(str_to_date(yourColumnName2, '%d/%m/%Y'))=yourValue2;Let us first create a table −mysql> create table DemoTable1924 ( UserName varchar(20), UserJoiningDate varchar(40) ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1924 values('Chris', '10/12/2010'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1924 values('David', '20/01/2011'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1924 values('Mike', '20/01/2010'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1924 values('Carol', ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
823 Views
Let us create a table −mysql> create table DemoTable1923 ( UserId int NOT NULL AUTO_INCREMENT PRIMARY KEY, UserName varchar(20) ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1923(UserId, UserName) select 101 as UserId, 'Chris' as UserName; Query OK, 1 row affected (0.00 sec) Records: 1 Duplicates: 0 Warnings: 0 mysql> insert into DemoTable1923(UserId, UserName) select 102 as UserId, 'Robert' as UserName; Query OK, 1 row affected (0.00 sec) Records: 1 Duplicates: 0 Warnings: 0 mysql> insert into DemoTable1923(UserId, UserName) ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
154 Views
Let us create a table −mysql> create table DemoTable1922 ( StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, StudentName varchar(20) ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1922(StudentName) values('Chris'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1922(StudentName) values('Robert'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1922(StudentName) values('David'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1922(StudentName) values('Mike'); Query OK, 1 row affected (0.00 sec)Display all records from the table using select statement −mysql> select * from DemoTable1922;This ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
114 Views
For random rows, you can use RAND(), whereas to fix a specific column, use ORDER BY clause. Let us create a table −mysql> create table DemoTable1921 ( Number int ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1921 values(40); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1921 values(80); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1921 values(820); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1921 values(10); Query OK, 1 row affected (0.00 sec)Display all records from the ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
9K+ Views
To group marks, use MySQL GROUP BY. To sum, use MySQL sum()function. Let us first create a table −mysql> create table DemoTable1920 ( StudentName varchar(20), StudentMarks int ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1920 values('Chris', 67); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1920 values('David', 97); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1920 values('Chris', 57); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1920 values('David', 45); Query OK, 1 row affected (0.00 sec) mysql> ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
457 Views
You can use DECLARE in a stored procedure. The syntax is as follows −declare yourVariableName yourDataType;To understand the above syntax, let us create a stored procedure:mysql> delimiter // mysql> create procedure square_demo(in Value int) begin declare magicValue int; set magicValue=Value; select concat('Your Square Value=',magicValue*magicValue) as Output; end ; // Query OK, 0 rows affected (0.00 sec) mysql> delimiter ;Now you can call a stored procedure using call command −mysql> call square_demo(15);This will produce the following output −+-----------------------+ | Output | +-----------------------+ | Your Square Value=225 | +-----------------------+ 1 row in set (0.00 sec) Query OK, 0 rows affected (0.00 sec)
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
2K+ Views
To fix the error, let us see how to create a user correctly. Let us create a user −mysql> create user 'Emma'@'localhost' IDENTIFIED BY 'emma_654'; Query OK, 0 rows affected (0.00 sec)Let us display all users along with host −mysql> select user, host from MySQL.user;This will produce the following output. The new user created above is visible in the below list of all users along with host −+------------------+-----------+ | user | host | +------------------+-----------+ | Bob | % | | Charlie ... Read More