AmitDiwan has Published 11365 Articles

Is SELECT * faster than 40 columns listing in MySQL?

AmitDiwan

AmitDiwan

Updated on 27-Sep-2019 07:39:55

96 Views

The SELECT * is slower than 40 columns listing. It’s a better choice to list the column names while using the SELECT query. Let us see a simple example and create a table −mysql> create table DemoTable(    Id int,    Name varchar(20),    Age int,    ZipCode varchar(20),   ... Read More

Get second largest marks from a MySQL table using subquery?

AmitDiwan

AmitDiwan

Updated on 27-Sep-2019 07:37:46

238 Views

Let us first create a table −mysql> create table DemoTable(    Marks int ); Query OK, 0 rows affected (1.34 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(78); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values(88); Query OK, 1 row ... Read More

MySQL query to count number of duplicate values in a table column

AmitDiwan

AmitDiwan

Updated on 27-Sep-2019 07:36:12

158 Views

Let us first create a table −mysql> create table DemoTable(    Data int ); Query OK, 0 rows affected (0.98 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(60); Query OK, 1 row affected (0.27 sec) mysql> insert into DemoTable values(40); Query OK, 1 row ... Read More

A single MySQL query to select value from first table and insert in the second?

AmitDiwan

AmitDiwan

Updated on 27-Sep-2019 07:34:35

151 Views

Let us first create a table −mysql> create table DemoTable1(    Value int ); Query OK, 0 rows affected (0.65 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1 values(67); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable1 values(46); Query OK, 1 row ... Read More

MySQL ENUM column match for quoted values

AmitDiwan

AmitDiwan

Updated on 27-Sep-2019 07:33:14

88 Views

Let us first create a table with ENUM type column −mysql> create table DemoTable(    isMarried ENUM('1', '0') ); Query OK, 0 rows affected (0.46 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('0'); Query OK, 1 row affected (0.08 sec) mysql> insert into DemoTable ... Read More

Order MySQL query by multiple ids?

AmitDiwan

AmitDiwan

Updated on 27-Sep-2019 07:31:48

252 Views

For this, use ORDER BY FIELD(). Let us first create a table −mysql> create table DemoTable(    ClientId varchar(40),    ClientName varchar(40) ); Query OK, 0 rows affected (0.55 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('987_John', 'John'); Query OK, 1 row affected (0.33 ... Read More

Display Timestamp before the current date in MySQL

AmitDiwan

AmitDiwan

Updated on 27-Sep-2019 07:29:31

111 Views

Let us first create a table −mysql> create table DemoTable(    ArrivalDate timestamp ); Query OK, 0 rows affected (1.96 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('2019-09-14 17:25:00'); Query OK, 1 row affected (0.26 sec) mysql> insert into DemoTable values('2019-09-13 17:25:00'); Query OK, ... Read More

MySQL query to concatenate all the values in each row based on the common matching ID

AmitDiwan

AmitDiwan

Updated on 27-Sep-2019 07:25:36

108 Views

Let us first create a table −mysql> create table DemoTable (    StudentId int,    StudentFirstName varchar(100),    StudentLastName varchar(100) ); Query OK, 0 rows affected (0.54 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(1000, 'Adam', 'Smith'); Query OK, 1 row affected (0.17 sec) ... Read More

MySQL query to sum the Product Price values from similar columns for same customers and display the result in the same column

AmitDiwan

AmitDiwan

Updated on 27-Sep-2019 07:22:26

369 Views

For this, use SUM() along with GROUP BY. Let us first create a table −mysql> create table DemoTable (    CustomerName varchar(100),    Product_1_Price int,    Product_2_Price int ); Query OK, 0 rows affected (0.73 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('John', 67, ... Read More

Display records by first fixing the first two values in a column and then using DISTINCT to display other values in MySQL

AmitDiwan

AmitDiwan

Updated on 27-Sep-2019 07:19:12

58 Views

Let us first create a table −mysql> create table DemoTable (    FirstName varchar(100) ); Query OK, 0 rows affected (0.96 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Chris'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('Robert'); Query OK, ... Read More

Advertisements