Found 4219 Articles for MySQLi

Set a custom value for NULL or empty values in MySQL

AmitDiwan
Updated on 30-Sep-2019 08:00:43

616 Views

Let us first create a table −mysql> create table DemoTable (    Value varchar(100) ); Query OK, 0 rows affected (0.75 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('100'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values(''); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable values('200'); Query OK, 1 row affected (0.06 sec) mysql> insert into DemoTable values(null); Query OK, 1 row affected (0.12 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce the following output −+-------+ | Value | +-------+ ... Read More

Find the number of logins between two dates in MySQL

AmitDiwan
Updated on 30-Sep-2019 07:59:03

115 Views

Use BETWEEN to find the logins between two dates. Let us first create a table −mysql> create table DemoTable (    Login datetime ); Query OK, 0 rows affected (0.66 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('2019-08-10'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values('2019-08-12'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values('2019-08-20'); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable values('2019-08-24'); Query OK, 1 row affected (0.12 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will ... Read More

Display multiple selected rows using MySQL IN()

AmitDiwan
Updated on 30-Sep-2019 07:57:35

452 Views

Let us first create a table −mysql> create table DemoTable1045 (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    FirstName varchar(100) )AUTO_INCREMENT=100; Query OK, 0 rows affected (0.62 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1045(FirstName) values('John'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable1045(FirstName) values('Chris'); Query OK, 1 row affected (0.27 sec) mysql> insert into DemoTable1045(FirstName) values('Robert'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable1045(FirstName) values('Mike'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1045(FirstName) values('Adam'); Query OK, 1 row affected (0.08 sec)Display all records ... Read More

Advanced sorting in MySQL to display strings beginning with J at the end even after ORDER BY

AmitDiwan
Updated on 30-Sep-2019 07:55:12

104 Views

For this, use ORDER BY LIKE operator. Let us first create a table −mysql> create table DemoTable (    Name varchar(100) ); Query OK, 0 rows affected (0.60 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('John'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values('Adam'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('Chris'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('Jace'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('David'); Query OK, 1 row affected (0.09 sec) mysql> insert into ... Read More

Display all products having the highest amount in a MySQL table with product details?

AmitDiwan
Updated on 30-Sep-2019 07:53:23

353 Views

Use MAX() along with subquery for this Here, MAX() is used to get the maximum amount. Let us first create a table −mysql> create table DemoTable (    ProductId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    ProductName varchar(100),    ProductAmount int ); Query OK, 0 rows affected (0.53 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(ProductName, ProductAmount) values('Product-1', 60); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable(ProductName, ProductAmount) values('Product-2', 40); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable(ProductName, ProductAmount) values('Product-3', 75); Query OK, 1 row affected (0.15 sec) mysql> ... Read More

How to compare the first date and the last date from a MySQL column with date records?

AmitDiwan
Updated on 30-Sep-2019 07:49:45

244 Views

To compare the first date with the last date, use TIME_TO_SEC() along with MAX() and MIN(). Let us first create a table −mysql> create table DemoTable (    UserName varchar(100),    UserPostDatetime datetime ); Query OK, 0 rows affected (0.65 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Adam', '2019-08-24 11:10:00'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('Adam', '2019-08-24 11:20:00'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values('Adam', '2019-08-24 11:50:00'); Query OK, 1 row affected (0.13 sec)Display all records from the table using select statement −mysql> ... Read More

How to get multiple rows in a single MySQL query?

AmitDiwan
Updated on 30-Sep-2019 07:48:08

572 Views

Let us first create a table −mysql> create table DemoTable (    Id int,    Name varchar(100) ); Query OK, 0 rows affected (0.60 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(100, 'Chris'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values(110, 'David'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values(120, 'Robert'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values(130, 'Mike'); Query OK, 1 row affected (0.13 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce the ... Read More

Can we use WHERE clause inside MySQL CASE statement?

AmitDiwan
Updated on 30-Sep-2019 07:46:16

210 Views

For this, use the CASE WHEN statement. Let us first create a table −mysql> create table DemoTable1040 (    Value1 int,    Value2 int,    Value3 int ); Query OK, 0 rows affected (0.65 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1040 values(10, 30, 1); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable1040 values(40, 20, 50); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable1040 values(80, 90, 100); Query OK, 1 row affected (0.11 sec)Display all records from the table using select statement −mysql> select *from DemoTable1040;This will produce the ... Read More

How to get left substring in MySQL from a column with file path? Display the entire file path string excluding the file name?

AmitDiwan
Updated on 30-Sep-2019 07:39:52

260 Views

To get the left substring, use LEFT() along with substring_index(). For example, let’s say the file path is −“/MyFile/JavaProgram/Hello.java “Here, we will see how to display the entire file path except for the file name i.e. −/MyFile/JavaProgram/Let us first create a table −mysql> create table DemoTable (    FileLocation text ); Query OK, 0 rows affected (0.57 secInsert some records in the table using insert command −mysql> insert into DemoTable values('/MyFile/JavaProgram/Hello.java'); Query OK, 1 row affected (0.27 sec) mysql> insert into DemoTable values('/C/AllPrograms/animation.gif'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values('/E/FavFile/ChatProgram.java'); Query OK, 1 row affected ... Read More

How to get the fourth highest value using MySQL query?

AmitDiwan
Updated on 30-Sep-2019 07:30:53

222 Views

To get the fourth-highest value, use LIMIT OFFSET along with ORDER BY. Let us first create a table −mysql> create table DemoTable (    Amount int ); Query OK, 0 rows affected (0.88 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(980); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values(670); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values(890); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values(995); Query OK, 1 row affected (0.25 sec) mysql> insert into DemoTable values(198); Query OK, 1 row affected ... Read More

Advertisements