AmitDiwan has Published 10740 Articles

MySQL query to replace backslash from a varchar column with preceding backslash string values

AmitDiwan

AmitDiwan

Updated on 26-Sep-2019 08:22:18

1K+ Views

Let us first create a table −mysql> create table DemoTable (    Title varchar(100) ); Query OK, 0 rows affected (0.57 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('\"MySQL'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('MongoDB\"'); Query OK, 1 ... Read More

Is it necessary to add DEFAULT NULL in MySQL?

AmitDiwan

AmitDiwan

Updated on 26-Sep-2019 08:19:44

2K+ Views

No, it isn’t necessary because without adding DEFAULT NULL, it gives NULL value. For example, let’s say you haven’t added DEFAULT NULL and inserted a record with no value, then the result would display the NULL value as the inserted value.Let us first create a table −mysql> create table DemoTable ... Read More

MySQL query to remove everything except the last 7 characters in column record

AmitDiwan

AmitDiwan

Updated on 26-Sep-2019 08:16:19

137 Views

Let us first create a table −mysql> create table DemoTable (    Strength text ); Query OK, 0 rows affected (0.51 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('John is a good programmer'); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable ... Read More

Implement CASE statement with WHEN clause to check for the existence of a record in MySQL

AmitDiwan

AmitDiwan

Updated on 26-Sep-2019 08:14:59

229 Views

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

How can I achieve similar result like using a loop in MySQL WHERE clause to display only alternate ID records?

AmitDiwan

AmitDiwan

Updated on 26-Sep-2019 08:13:29

177 Views

Get similar results using MySQL IN(). Let us first create a table −mysql> create table DemoTable (    ClientId int,    ClientName varchar(100),    ClientAge int ); Query OK, 0 rows affected (0.70 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(100, 'Chris', 34); Query ... Read More

MySQL query to order by current day and month?

AmitDiwan

AmitDiwan

Updated on 26-Sep-2019 08:10:26

343 Views

For this, you can use the ORDER BY CASE statement. Let us first create a table −mysql> create table DemoTable (    DueDate date ); Query OK, 0 rows affected (0.56 sec)Note − Let’s say the current date is 2019-07-22.Insert some records in the table using insert command −mysql> insert ... Read More

Fix a row value and then ORDER BY DESC rest of the values in MySQL

AmitDiwan

AmitDiwan

Updated on 26-Sep-2019 08:08:56

127 Views

Let us first create a table −mysql> create table DemoTable (    id int ); Query OK, 0 rows affected (0.52 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(10); Query OK, 1 row affected (0.43 sec) mysql> insert into DemoTable values(7); Query OK, 1 ... Read More

How to remove unconvertable characters to ASCII with SELECT in MySQL?

AmitDiwan

AmitDiwan

Updated on 26-Sep-2019 08:06:59

2K+ Views

Let us first create a table −mysql> create table DemoTable (    Value varchar(100) ); Query OK, 0 rows affected (0.57 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('€986'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('§97'); Query OK, 1 ... Read More

Select distinct values from two columns in MySQL?

AmitDiwan

AmitDiwan

Updated on 26-Sep-2019 08:04:17

583 Views

To select distinct values from two columns, use UNION. Let us first create a table −mysql> create table DemoTable1 (    Value1 int ); Query OK, 0 rows affected (0.56 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1 values(1); Query OK, 1 row affected (0.13 ... Read More

Write a single MySQL query to return the ID from the corresponding row which is a NOT NULL value

AmitDiwan

AmitDiwan

Updated on 26-Sep-2019 08:00:29

124 Views

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

Advertisements