AmitDiwan has Published 10740 Articles

Maintain the custom order of the IDs passed in MySQL

AmitDiwan

AmitDiwan

Updated on 12-Dec-2019 06:23:51

261 Views

To maintain the custom order of IDs, use ORDER BY CASE statement. Let us first create a table −mysql> create table DemoTable1550    -> (    -> Id int,    -> Name varchar(20)    -> ); Query OK, 0 rows affected (0.61 sec)Insert some records in the table using insert ... Read More

How to insert date record to the same table with different date formats with MySQL?

AmitDiwan

AmitDiwan

Updated on 12-Dec-2019 06:22:41

434 Views

For this, you can use the INSERT INTO SELECT statement. To format the date, use the DATE_FORMAT() function. Let us first create a table −mysql> create table DemoTable    -> (    -> DateOfJoining datetime,    -> JoiningDate text    -> ); Query OK, 0 rows affected (0.79 sec)Insert some ... Read More

Difference between SHOW INDEX, SHOW INDEXES and SHOW KEYS in MySQL?

AmitDiwan

AmitDiwan

Updated on 12-Dec-2019 06:21:48

310 Views

There is no difference between show index, show indexes and show keys. They have similar meaning.Let us first create a table −mysql> create table DemoTable1549    -> (    -> EmployeeId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> EmployeeName varchar(20)    -> ); Query OK, 0 rows affected (0.82 ... Read More

MySQL query to sort by certain last string character?

AmitDiwan

AmitDiwan

Updated on 12-Dec-2019 06:17:47

352 Views

For this, you can use the CASE statement. To sort, use the ORDER BY clause. Let us first create a table −mysql> create table DemoTable    -> (    -> ClientId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> ClientName varchar(20)    -> ); Query OK, 0 rows affected (0.54 ... Read More

MySQL query to fetch specific records matched from an array (comma separated values)

AmitDiwan

AmitDiwan

Updated on 12-Dec-2019 06:15:57

923 Views

To fetch records from comma separated values, use MySQL FIND_IN_SET(). Let us first create a table −mysql> create table DemoTable1548    -> (    -> StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> StudentName varchar(20),    -> ArrayListOfMarks varchar(100)    -> ); Query OK, 0 rows affected (0.88 sec)Insert ... Read More

Fetch student records whose result declared 12 days before the current date in MYSQL

AmitDiwan

AmitDiwan

Updated on 12-Dec-2019 06:14:16

223 Views

For this, you need to compare and find the difference between the current date and the result date of students. This can be done with AND operator along with DATEDIFF().Let us first create a table −mysql> create table DemoTable1547    -> (    -> StudentId int NOT NULL AUTO_INCREMENT PRIMARY ... Read More

MySQL query to format numbers which has space between digit?

AmitDiwan

AmitDiwan

Updated on 12-Dec-2019 06:11:52

297 Views

Let us first create a table −mysql> create table DemoTable1546    -> (    -> Number varchar(20)    -> ); Query OK, 0 rows affected (0.99 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1546 values('145 78 90'); Query OK, 1 row affected (0.17 sec) mysql> ... Read More

MySQL procedure to display a “select” statement twice

AmitDiwan

AmitDiwan

Updated on 12-Dec-2019 06:10:55

236 Views

To understand, let us create a stored procedure. Here, we have 2 select statements in the stored procedure −mysql> DELIMITER // mysql> CREATE PROCEDURE select_statement()    -> BEGIN    ->    SELECT "HI" AS `FIRST VALUE`;    ->    SELECT "HELLO" AS `SECOND VALUE`;    -> END    -> // ... Read More

Set different IDs for records with conditions using a single MySQL query

AmitDiwan

AmitDiwan

Updated on 12-Dec-2019 06:09:41

219 Views

For conditions, use CASE statement in MySQL. Let us first create a table −mysql> create table DemoTable1545    -> (    -> Id int,    -> FirstName varchar(20)    -> ); Query OK, 0 rows affected (1.65 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1545 ... Read More

MySQL query to remove text between square brackets?

AmitDiwan

AmitDiwan

Updated on 12-Dec-2019 06:08:50

1K+ Views

Let us first create a table −mysql> create table DemoTable    -> (    -> Name text    -> ); Query OK, 0 rows affected (0.47 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('John [John] Smith'); Query OK, 1 row affected (0.30 sec) mysql> ... Read More

Advertisements