AmitDiwan has Published 10740 Articles

How to select different values from same column and display them in different columns with MySQL?

AmitDiwan

AmitDiwan

Updated on 09-Oct-2019 11:38:11

2K+ Views

To select different values on the basis of condition, use CASE statement. Let us first create a table −mysql> create table DemoTable (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    Name varchar(40), Score int ) ; Query OK, 0 rows affected (0.54 sec)Insert some records in the table ... Read More

Randomly SELECT distinct rows in a MySQL table?

AmitDiwan

AmitDiwan

Updated on 09-Oct-2019 11:32:15

703 Views

To randomly select rows, use ORDER BY RAND() with LIMIT. Use DISTINCT for distinct rows. Let us first see an example and create a table −mysql> create table DemoTable (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    Name varchar(40) ); Query OK, 0 rows affected (0.54 sec)Insert some ... Read More

Use delimiter correctly in a MySQL stored procedure to avoid BEGIN/END statements errors

AmitDiwan

AmitDiwan

Updated on 09-Oct-2019 11:20:01

192 Views

Such errors arise when you avoid using the DELIMITER concept. Let us see an example and run a query for stored procedure −mysql> DELIMITER // mysql> CREATE PROCEDURE correct_procedure()    BEGIN    SELECT 'Hello MySQL !!!';    END // Query OK, 0 rows affected (0.12 sec) mysql> DELIMITER ;Following is ... Read More

Set new delay time in a MySQL column

AmitDiwan

AmitDiwan

Updated on 09-Oct-2019 11:18:35

258 Views

To set new delay time, use INTERVAL and update the column wth SETa clause and UPDATE command. Let us first create a table −mysql> create table DemoTable (    DelayTime time ); Query OK, 0 rows affected (1.21 sec)Insert some records in the table using insert command −mysql> insert into ... Read More

MySQL RegEx to find lines containing N semi-colons?

AmitDiwan

AmitDiwan

Updated on 09-Oct-2019 11:15:40

230 Views

Let us first create a table −mysql> create table DemoTable (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY ,    Title text ); Query OK, 0 rows affected (0.88 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(Title) values('This is; a; MySQL;Tutorial'); Query OK, 1 ... Read More

How to find tables with a specific column name in MySQL?

AmitDiwan

AmitDiwan

Updated on 09-Oct-2019 11:12:56

1K+ Views

To find column names, use information_schema.columns. Following is the syntax −select distinct table_name from information_schema.columns where column_name like '%yourSearchValue%' and table_schema=database();Let us implement the above syntax in order to find column names across various table. Here, we want only table names with a specific column name word “Client” −mysql> select ... Read More

Adding characters in values for an existing int column in MySQL?

AmitDiwan

AmitDiwan

Updated on 09-Oct-2019 11:08:26

450 Views

To add characters to an existing int column values, use MySQL CONCAT(). Let us first create a table −mysql> create table DemoTable (    Amount int ); Query OK, 0 rows affected (1.44 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(709); Query OK, 1 ... Read More

Pull MySQL records for the last 60 minutes?

AmitDiwan

AmitDiwan

Updated on 09-Oct-2019 10:50:28

827 Views

To pull records for the last 60 minutes, use MySQL INTERVAL as shown in the below syntax −select *from yourTableName where yourColumnName > now() - interval 60 minute;Let us first create a table −mysql> create table DemoTable (    ArrivalTime datetime ); Query OK, 0 rows affected (0.61 sec)Let us ... Read More

How to select records beginning with certain numbers in MySQL?

AmitDiwan

AmitDiwan

Updated on 09-Oct-2019 10:48:05

4K+ Views

The optimal solution to select records beginning with certain numbers, use MySQL LIKE operator. Let us first create a table −mysql> create table DemoTable (    ClientId bigint,    ClientName varchar(40) ); Query OK, 0 rows affected (0.82 sec)Insert some records in the table using insert command −mysql> insert into ... Read More

Delete selective multiple records using MySQL DELETE query

AmitDiwan

AmitDiwan

Updated on 09-Oct-2019 10:45:58

503 Views

For selective multiple records, use MySQL IN(). To delete them, use MySQL DELETE. Let us first create a table −mysql> create table DemoTable (    ClientId varchar(40),    ClientName varchar(50) ); Query OK, 0 rows affected (0.62 sec)Insert some records in the table using insert command −mysql> insert into DemoTable ... Read More

Advertisements