AmitDiwan has Published 10740 Articles

Fetch records from comma separated values using MySQL IN()?

AmitDiwan

AmitDiwan

Updated on 12-Nov-2019 05:42:44

2K+ Views

Use FIND_IN_SET() instead of MySQL IN(). Let us first create a −mysql> create table DemoTable1423    -> (    -> CountryName varchar(100)    -> ); Query OK, 0 rows affected (0.51 sec)Insert some records in the table using insert −mysql> insert into DemoTable1423 values('AUS, UK'); Query OK, 1 row affected ... Read More

MySQL query to select all data between range of two dates?

AmitDiwan

AmitDiwan

Updated on 12-Nov-2019 05:40:07

719 Views

To select all data between range of two dates, use MySQL BETWEEN −select * from yourTableName where yourColumnName between yourDateValue1 and yourDateValue2;Let us first create a −mysql> create table DemoTable1422    -> (    -> EmployeeId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> EmployeeName varchar(20),    -> EmployeeJoiningDate date ... Read More

Replace records based on conditions in MySQL?

AmitDiwan

AmitDiwan

Updated on 12-Nov-2019 05:36:25

833 Views

To set conditions, use MySQL CASE statement. Let us first create a −mysql> create table DemoTable1481    -> (    -> PlayerScore int    -> ); Query OK, 0 rows affected (0.42 sec)Insert some records in the table using insert −mysql> insert into DemoTable1481 values(454); Query OK, 1 row affected ... Read More

Can we fetch multiple values with MySQL WHERE Clause?

AmitDiwan

AmitDiwan

Updated on 12-Nov-2019 05:34:46

264 Views

Yes, we can fetch, but use MySQL OR for conditions. Let us first create a −mysql> create table DemoTable1421    -> (    -> EmployeeId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> EmployeeName varchar(20),    -> EmployeeSalary int    -> ); Query OK, 0 rows affected (0.82 sec)Insert some ... Read More

How to update multiple rows using single WHERE clause in MySQL?

AmitDiwan

AmitDiwan

Updated on 12-Nov-2019 05:32:00

956 Views

For this, you can use MySQL IN(). Let us first create a −mysql> create table DemoTable1420    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> FirstName varchar(20),    -> LastName varchar(20),    -> Age int    -> ); Query OK, 0 rows affected (1.12 sec)Insert ... Read More

Convert MySQL time from HH:MM:SS to HH:MM

AmitDiwan

AmitDiwan

Updated on 12-Nov-2019 05:28:50

976 Views

To convert, use MySQL TIME_FORMAT(). Let us first create a −mysql> create table DemoTable1419    -> (    -> ArrivalTime time    -> ); Query OK, 0 rows affected (0.78 sec)Insert some records in the table using insert command. Here, we have inserted time records −mysql> insert into DemoTable1419 values('12:30:45'); ... Read More

How to use MySQL SELECT LEFT to fetch the records containing string with slash

AmitDiwan

AmitDiwan

Updated on 12-Nov-2019 05:27:17

120 Views

Let us first create a −mysql> create table DemoTable1418    -> (    -> EmployeeCode text    -> ); Query OK, 0 rows affected (0.51 sec)Insert some records in the table using insert −mysql> insert into DemoTable1418 values('EMP-2110/Carol'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1418 values('EMP-1900/David'); ... Read More

Order date records and fetch the 2nd ordered record in MySQL

AmitDiwan

AmitDiwan

Updated on 12-Nov-2019 05:24:35

136 Views

To order, use ORDER BY and to fetch only the 2nd ordered record, use MySQL LIMIT and set offset as well. Let us first create a −mysql> create table DemoTable1417    -> (    -> CustomerId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> CustomerName varchar(20),    -> ShippingDate date ... Read More

Fetch substrings from a string with words separated by slash in MySQL?

AmitDiwan

AmitDiwan

Updated on 12-Nov-2019 05:21:14

223 Views

For this, you can use SUBSTRING_INDEX(). Let us first create a −mysql> create table DemoTable1416    -> (    -> StudentCode varchar(100)    -> ); Query OK, 0 rows affected (1.56 sec)Insert some records in the table using insert −mysql> insert into DemoTable1416 values('101/John/Smith'); Query OK, 1 row affected (0.13 ... Read More

How to sum the values in the table by month with MySQL?

AmitDiwan

AmitDiwan

Updated on 12-Nov-2019 05:19:52

3K+ Views

For this, use EXTRACT(), that would allow you to extract specific month records. For example, to add all the prices in January (irrespective of the year).Let us first create a −mysql> create table DemoTable1415    -> (    -> ProductPurchaseDate date,    -> ProductPrice int    -> ); Query OK, ... Read More

Advertisements