Found 4378 Articles for MySQL

Search text containing a new line in MySQL?

AmitDiwan
Updated on 06-Jul-2020 06:00:18

560 Views

You can use REGEXP. Let us first create a table −mysql> create table DemoTable (    Name varchar(100) ); Query OK, 0 rows affected (1.61 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('JohnSmith'); Query OK, 1 row affected (0.73 sec) mysql> insert into DemoTable values('John Doe'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values('DavidMiller'); Query OK, 1 row affected (0.24 sec) mysql> insert into DemoTable values('Carol Taylor'); Query OK, 1 row affected (0.27 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce the following ... Read More

Use LIKE % to fetch multiple values in a single MySQL query

AmitDiwan
Updated on 30-Sep-2019 07:00:04

3K+ Views

To fetch multiple values wit LIKE, use the LIKE operator along with OR operator. Let us first create a table −mysql> create table DemoTable1027 (    Id int,    Name varchar(100) ); Query OK, 0 rows affected (1.64 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1027 values(100, 'John'); Query OK, 1 row affected (0.72 sec) mysql> insert into DemoTable1027 values(20, 'Chris'); Query OK, 1 row affected (0.56 sec) mysql> insert into DemoTable1027 values(200, 'Robert'); Query OK, 1 row affected (0.84 sec) mysql> insert into DemoTable1027 values(400, 'Mike'); Query OK, 1 row affected (0.47 sec)Display all ... Read More

MySQL select query to fetch data with null value?

AmitDiwan
Updated on 30-Sep-2019 06:57:06

398 Views

Let us first create a table −mysql> create table DemoTable (    CustomerName varchar(100),    CustomerCountryName varchar(100) ); Query OK, 0 rows affected (0.95 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Chris', 'US'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values('Bob', 'UK'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values('Carol', NULL); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('David', 'AUS'); Query OK, 1 row affected (0.32 sec) mysql> insert into DemoTable values('Mike', NULL); Query OK, 1 row affected (0.18 sec)Display all records ... Read More

Show column value twice in MySQL Select?

AmitDiwan
Updated on 30-Sep-2019 06:54:42

213 Views

You can use concat(). Let us first create a table −mysql> create table DemoTable (    Value int ); Query OK, 0 rows affected (0.73 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(100); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values(200); Query OK, 1 row affected (0.08 sec) mysql> insert into DemoTable values(100); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values(200); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values(200); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values(100); Query ... Read More

Get count of zeros for columns values declared with INT type in MySQL

AmitDiwan
Updated on 30-Sep-2019 06:52:26

184 Views

For this, you can use LENGTH() along with REPLACE(). Let us first create a table −mysql> create table DemoTable (    Value int ); Query OK, 0 rows affected (1.22 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(10002000); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable values(00000); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values(400560); Query OK, 1 row affected (0.19 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce the following output −+----------+ | Value    | +----------+ | 10002000 ... Read More

Return value from a row if it is NOT NULL, else return the other row value in another column with MySQL

AmitDiwan
Updated on 30-Sep-2019 06:50:15

199 Views

For this, you can use IFNULL(). Let us first create a table −mysql> create table DemoTable (    FirstName varchar(100),    LastName varchar(100) ); Query OK, 0 rows affected (0.62 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('John', 'Doe'); Query OK, 1 row affected (0.29 sec) mysql> insert into DemoTable values(NULL, 'Taylor'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('David', NULL); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values(NULL, 'Miller'); Query OK, 1 row affected (0.12 sec)Display all records from the table using select statement −mysql> ... Read More

MySQL query to compare and display only the rows with NULL values

AmitDiwan
Updated on 30-Sep-2019 06:48:14

112 Views

For this, you can use IFNULL(). Let us first create a table −mysql> create table DemoTable (    Value1 int,    Value2 int ); Query OK, 0 rows affected (0.75 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(10, NULL); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values(20, 40); Query OK, 1 row affected (0.27 sec) mysql> insert into DemoTable values(3, NULL); Query OK, 1 row affected (0.20 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce the following output −+--------+--------+ | Value1 | Value2 ... Read More

MySQL UNIQUE declaration to avoid inserting duplicate values?

AmitDiwan
Updated on 30-Sep-2019 06:46:13

194 Views

Following is the declaration for a UNIQUE clause in MySQL −create table yourTableName (    yourColumnName1 dataType,    yourColumnName2 dataType,    UNIQUE(yourColumnName1),    UNIQUE(yourColumnName1) );Let us first create a table −mysql> create table DemoTable (    Value int,    Value2 int,    UNIQUE(Value),    UNIQUE(Value2) ); Query OK, 0 rows affected (13.98 sec)Insert some records in the table using insert command. Here, duplicate records won’t insert because we have used UNIQUE above −mysql> insert into DemoTable values(10, 20) ; Query OK, 1 row affected (0.32 sec) mysql> insert into DemoTable values(10, 30); ERROR 1062 (23000): Duplicate entry '10' for key ... Read More

Display distinct dates in MySQL from a column with date records

AmitDiwan
Updated on 30-Sep-2019 06:44:28

416 Views

Let us first create a table −mysql> create table DemoTable (    AdmissionDate datetime ); Query OK, 0 rows affected (8.99 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('2010-01-10 12:30:45'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('2010-01-10 12:30:45'); Query OK, 1 row affected (0.46 sec) mysql> insert into DemoTable values('2010-01-10 12:30:45'); Query OK, 1 row affected (0.71 sec) mysql> insert into DemoTable values('2010-01-12 12:30:45'); Query OK, 1 row affected (1.22 sec) mysql> insert into DemoTable values('2010-01-20 12:30:45'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values('2010-01-20 ... Read More

Check if a number is Palindrome in PL/SQLs

Arnab Chakraborty
Updated on 27-Sep-2019 10:42:03

7K+ Views

In this section we will see how to check whether a number is Palindrome or not using the PL/SQL. In PL/SQL code, some group of commands are arranged within a block of related declaration of statements.A number is palindrome if the number, and the reverse of that number are same. Suppose a number 12321, this is palindrome, but 12345 is not a palindrome.ExampleDECLARE    n number;    m number;    temp number:=0;    rem number; BEGIN    n :=12321;    m :=n;    while n>0    loop       rem := mod(n, 10);       temp := (temp*10)+rem; ... Read More

Advertisements