Found 4378 Articles for MySQL

How to create a column of months from date and display sum of the corresponding column wherein you find duplicate dates?

AmitDiwan
Updated on 12-Dec-2019 05:49:47

27 Views

For this can use DATE_FORMAT() in MySQL. Let us first create a table −mysql> create table DemoTable    -> (    -> PurchaseDate date,    -> Amount int    -> ); Query OK, 0 rows affected (0.52 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('2019-10-12', 500); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('2018-10-12', 1000); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values('2019-01-10', 600); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('2018-10-12', 600); Query OK, 1 row affected (0.15 sec) mysql> insert ... Read More

How to write a single MySQL query for displaying a value for multiple inputs?

AmitDiwan
Updated on 12-Dec-2019 05:47:28

252 Views

For this, use BETWEEN keyword. Let us first create a table −mysql> create table DemoTable1537    -> (    -> StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> StudentName varchar(20)    -> ); Query OK, 0 rows affected (0.72 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1537(StudentName) values('Chris'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1537(StudentName) values('Bob'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable1537(StudentName) values('Sam'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable1537(StudentName) values('Mike'); Query OK, 1 row affected (0.16 sec) mysql> insert into ... Read More

A single MySQL query to search multiple words from different column values

AmitDiwan
Updated on 12-Dec-2019 05:44:51

1K+ Views

For this, you can use WHERE clause with multiple LIKE. Let us first create a table −mysql> create table DemoTable1536    -> (    -> Sentence text    -> ); Query OK, 0 rows affected (0.51 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1536 values('I like MySQL database.'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable1536 values('Java is an Object Oriented Programming Language'); Query OK, 1 row affected (0.30 sec) mysql> insert into DemoTable1536 values('I only like data structure'); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable1536 values('MongoDB is ... Read More

MySQL Order by beginning letter?

AmitDiwan
Updated on 12-Dec-2019 05:42:42

431 Views

To order by the first letter, use ORDER BY CASE statement. Let us first create a table −mysql> create table DemoTable1535    -> (    -> Value varchar(100)    -> ); Query OK, 0 rows affected (2.26 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1535 values('MySQL is good relational database.'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable1535 values('is MySQL easy to lean'); Query OK, 1 row affected (0.35 sec) mysql> insert into DemoTable1535 values('You need to start basic SQL'); Query OK, 1 row affected (0.35 sec)Display all records from the table ... Read More

Using Update statement with TINYINT in MySQL?

AmitDiwan
Updated on 12-Dec-2019 05:46:35

1K+ Views

Let us first create a table. We have set one of the columns with type TINYINT −mysql> create table DemoTable    -> (    -> EmployeeId int,    -> isMarried tinyint    -> ); Query OK, 0 rows affected (6.84 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(101, true); Query OK, 1 row affected (1.94 sec) mysql> insert into DemoTable values(102, false); Query OK, 1 row affected (0.76 sec) mysql> insert into DemoTable values(103, true); Query OK, 1 row affected (1.14 sec) mysql> insert into DemoTable values(104, true); Query OK, 1 row affected (1.22 ... Read More

Implement multiple LIKE operators in a single MySQL query

AmitDiwan
Updated on 12-Dec-2019 05:40:27

709 Views

To implement multiple LIKE clauses, the syntax is as follows −select * from yourTableName  where yourColumnName1 LIKE ('%yourValue1%' or yourColumnName2 LIKE '%yourValue2%') or (yourColumnName3 LIKE '%yourValue3');Let us first create a table −mysql> create table DemoTable1534    -> (    -> ClientId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> ClientName varchar(20),    -> ClientAge int,    -> ClientCountryName varchar(20)    -> ); Query OK, 0 rows affected (0.78 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1534(ClientName, ClientAge, ClientCountryName) values('Chris Brown', 29, 'AUS'); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable1534(ClientName, ClientAge, ClientCountryName) ... Read More

Select equal or nearest greater number from table in MySQL

AmitDiwan
Updated on 03-Mar-2020 07:04:48

586 Views

Let us first create a table −mysql> create table DemoTable    -> (    -> Value int    -> ); Query OK, 0 rows affected (1.33 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(25); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values(75); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values(100); 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 following output −+-------+ | Value | +-------+ |    25 | |   ... Read More

Order a column in MySQL with IP Address records?

AmitDiwan
Updated on 12-Dec-2019 05:35:07

453 Views

For this, use INET_ATON() in MySQL. The INET_ATON() method would allow a user to convert IP Address records to a number and then we can use ORDER BY to order them.Let us first create a table −mysql> create table DemoTable    -> (    -> IpAddress varchar(50)    -> ); Query OK, 0 rows affected (1.36 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('192.168.110.78'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values('192.168.110.87'); Query OK, 1 row affected (0.27 sec) mysql> insert into DemoTable values('192.168.110.75'); Query OK, 1 row affected (0.26 ... Read More

MySQL query to select maximum and minimum salary row?

AmitDiwan
Updated on 12-Dec-2019 05:32:20

742 Views

For this, use sub query along with MIN() and MAX(). To display both the maximum and minimum value, use UNION ALL. Let us first create a table −mysql> create table DemoTable    -> (    -> EmployeeName varchar(20),    -> EmployeeSalary int    -> ); Query OK, 0 rows affected (0.70 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Bob', 8800); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('Chris', 9800); Query OK, 1 row affected (0.63 sec) mysql> insert into DemoTable values('David', 7600); Query OK, 1 row affected (0.11 sec) mysql> ... Read More

Count(*) rows from multiple tables in MySQL?

AmitDiwan
Updated on 12-Dec-2019 05:36:17

1K+ Views

To count rows from multiple tables in MySQL, the syntax is as follows −Select     (select count(*) from yourTableName1) as anyAliasName1,     (select count(*) from yourTableName2) as anyAliasName2     from dual;Let us first create a table −mysql> create table DemoTable1    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY    -> ); Query OK, 0 rows affected (0.56 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1 values(), (), (), (), (), (); Query OK, 6 rows affected (0.24 sec) Records: 6  Duplicates: 0  Warnings: 0Display all records from the ... Read More

Advertisements