AmitDiwan has Published 10740 Articles

How to ORDER BY grouped fields in MySQL?

AmitDiwan

AmitDiwan

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

145 Views

To ORDER BY grouped fields, use ORDER BY CASE along with IN(). CASE evaluates different conditions whereas ORDER BY sort values in ascending or descending order. The MySQL IN() is used to find a match.Let us first create a table −mysql> create table DemoTable (    Value varchar(40) ); Query ... Read More

How to check if value exists with MySQL SELECT 1?

AmitDiwan

AmitDiwan

Updated on 07-Oct-2019 12:06:47

403 Views

Use SELECT 1 for this as in the below syntax −select 1 from yourTableName where yourColumnName=yourValue;If the above returns 1, that means value exists in the MySQL database. Let us first see an example and create a table −mysql> create table DemoTable (    StudentId int NOT NULL AUTO_INCREMENT PRIMARY ... Read More

MySQL CASE statement to place custom values in place of NULL

AmitDiwan

AmitDiwan

Updated on 07-Oct-2019 12:04:05

203 Views

Let us first create a table −mysql> create table DemoTable (    FirstName varchar(20) ); Query OK, 0 rows affected (1.15 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('John'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values(NULL); Query OK, 1 ... Read More

MySQL query to return multiple row records with AND & OR operator

AmitDiwan

AmitDiwan

Updated on 07-Oct-2019 11:55:50

481 Views

Let us first create a table −mysql> create table DemoTable (    StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    StudentName varchar(40),    StudentMathMarks int,    StudentMySQLMarks int,    status ENUM('ACTIVE', 'INACTIVE') ); Query OK, 0 rows affected (0.47 sec)Insert some records in the table using insert command −mysql> insert ... Read More

Difference between BIGINT and BIGINT(20) in MySQL?

AmitDiwan

AmitDiwan

Updated on 07-Oct-2019 11:49:55

4K+ Views

The only difference between BIGINT and BIGINT(20) is for displaying width. The 20 can be used for displaying width.Let us see an example and create a table. Here, we have set BIGINT(20) −mysql> create table DemoTable (    Number bigint(20) zerofill ); Query OK, 0 rows affected (0.58 sec)Insert some ... Read More

How to use MySQL LIKE clause to fetch multiple values beginning with “Joh”

AmitDiwan

AmitDiwan

Updated on 07-Oct-2019 11:47:15

218 Views

Let us first create a table −mysql> create table DemoTable (    Name varchar(40) ); Query OK, 0 rows affected (0.55 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('John'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values('Sam'); Query OK, 1 ... Read More

Get left part of the string on the basis of last occurrence of delimiter in MySQL?

AmitDiwan

AmitDiwan

Updated on 07-Oct-2019 11:42:27

207 Views

For this, use LEFT() method. For manipulation, we have used the LOCATE() and the REVERSE() method.Let us first create a table −mysql> create table DemoTable (    Title text ); Query OK, 0 rows affected (0.52 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('$/This$is[MySQL]$/MySQL[FirstClass]$MySQL[SecondClass]'); ... Read More

MySQL string manipulation to count only sub-part of duplicate values in IP ADDRESS records?

AmitDiwan

AmitDiwan

Updated on 07-Oct-2019 11:40:02

177 Views

For such string manipulations, you need to use MySQL SUBSTRING_INDEX(). Let us first create a table −mysql> create table DemoTable (    SystemIpAddress text ); Query OK, 0 rows affected (0.58 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('192.168.130.67'); Query OK, 1 row affected ... Read More

Is there a need to insert auto_increment column values in MySQL while using INSERT statement?

AmitDiwan

AmitDiwan

Updated on 07-Oct-2019 11:34:56

164 Views

No, there’s no need to insert auto_increment column values, since it begins from 1 and inserts on its own. This is because we have set it as auto increment. Let us first create a table −mysql> create table DemoTable (    EmployeeId int NOT NULL AUTO_INCREMENT,    EmployeeName varchar(30),   ... Read More

MySQL query to replace a column value

AmitDiwan

AmitDiwan

Updated on 07-Oct-2019 11:30:23

432 Views

Let us first create a table −mysql> create table DemoTable (    StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    Score int ); Query OK, 0 rows affected (0.45 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(Score) values(56); Query OK, 1 row affected (0.24 sec) ... Read More

Advertisements