MySQL Articles

Page 145 of 355

How to find rows with exact value in one or more columns with MySQL?

AmitDiwan
AmitDiwan
Updated on 26-Dec-2019 496 Views

For this, you can use GROUP BY HAVING with subquery. Let us first create a table −mysql> create table DemoTable1861      (      Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,      Name varchar(20),      Marks int      ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1861(Name, Marks) values('John', 45); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1861(Name, Marks) values('Chris', 74); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1861(Name, Marks) values('David', 89); Query OK, 1 row affected (0.00 sec) ...

Read More

How to use an OUT parameter / read data with SELECT from table in a MySQL procedure?

AmitDiwan
AmitDiwan
Updated on 26-Dec-2019 607 Views

For this, you can use SELECT INTO. Let us first create a table −mysql> create table DemoTable1860      (      Amount int      ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1860 values(1590); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1860 values(410); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1860 values(3000); Query OK, 1 row affected (0.00 sec)Display all records from the table using select statement −Mysql> select * from DemoTable1860; This will produce the following output −+--------+ | Amount ...

Read More

Is there an easy way to rename a table in a MySQL procedure?

AmitDiwan
AmitDiwan
Updated on 26-Dec-2019 259 Views

Yes, use the ALTER command with RENAME. Let us first create a table −mysql> create table DemoTable1859      (      Id int      ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1859 values(101); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1859 values(102); Query OK, 1 row affected (0.00 sec)Display all records from the table using select statement −mysql> select * from DemoTable1859; This will produce the following output −+------+ | Id   | +------+ |  101 | |  102 | +------+ 2 rows ...

Read More

Find duplicate column values in MySQL and display them

AmitDiwan
AmitDiwan
Updated on 26-Dec-2019 724 Views

For this, use GROUP BY HAVING clause. Let us first create a table −mysql> create table DemoTable1858      (      ModelNumber varchar(50)      ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1858 values('Audi A4'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1858 values('Audi A6'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1858 values('Audi A4'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1858 values('Audi Q5'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1858 values('Audi R8'); ...

Read More

MySQL query to get all characters before a specific character hyphen

AmitDiwan
AmitDiwan
Updated on 26-Dec-2019 1K+ Views

For this, you can use SUBSTRING_INDEX(). Let us first create a table −mysql> create table DemoTable1857      (      Name varchar(20)      ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1857 values('John-Smith'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1857 values('Brown-Chris'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1857 values('David-Carol-Miller'); Query OK, 1 row affected (0.00 sec)Display all records from the table using select statement −mysql> select * from DemoTable1857; This will produce the following output −+--------------------+ | Name   ...

Read More

Using GROUP_CONCAT() on bit fields returns garbage in MySQL? How to fix?

AmitDiwan
AmitDiwan
Updated on 26-Dec-2019 202 Views

To fix, use group_concat() with addition of 0 with column. Let us first create a table −mysql> create table DemoTable1856      (      Id int,      Value bit(1)      ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1856 values(101, 1); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1856 values(102, 0); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1856 values(101, 0); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1856 values(102, 1); Query OK, 1 row affected (0.00 ...

Read More

Which MySQL Datatype should be used for storing BloodType?

AmitDiwan
AmitDiwan
Updated on 26-Dec-2019 1K+ Views

To store BloodType, use varchar(3) or ENUM. Let us first create a table −mysql> create table DemoTable1855      (      BloodType varchar(3)      ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1855 values('A+'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1855 values('A-'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1855 values('B+'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1855 values('B-'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1855 values('AB+'); Query OK, 1 row affected ...

Read More

Distinct number of specific items in list with MySQL

AmitDiwan
AmitDiwan
Updated on 26-Dec-2019 232 Views

To find distinct number of specific items, use COUNT() along with GROUP BY clause. Let us first create a table −mysql> create table DemoTable1854      (      Name varchar(20)      ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1854 values('John-Smith'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1854 values('Chris-Brown'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1854 values('Adam-Smith'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1854 values('John-Doe'); Query OK, 1 row affected (0.00 sec) mysql> insert into ...

Read More

Why does comparing types in MySQL won't raise an error?

AmitDiwan
AmitDiwan
Updated on 26-Dec-2019 173 Views

If you try to compare string to int, MySQL won’t raise an error because it converts string to int. Let us first create a table −mysql> create table DemoTable1852      (      Value1 varchar(20),      Value2 int      ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1852 values('1John', 1); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1852 values('John', 1); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1852 values('1', 1); Query OK, 1 row affected (0.00 sec) mysql> insert into ...

Read More

Delete records where timestamp older than 5 minutes in MySQL?

AmitDiwan
AmitDiwan
Updated on 26-Dec-2019 2K+ Views

For this, use DELETE command. Let us first create a table −mysql> create table DemoTable1851      (      DueDate datetime      ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1851 values('2019-12-03 21:30:35'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1851 values('2019-12-03 21:45:00'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1851 values('2019-12-03 21:34:00'); Query OK, 1 row affected (0.00 sec)Display all records from the table using select statement −mysql> select * from DemoTable1851; This will produce the following output −+---------------------+ | ...

Read More
Showing 1441–1450 of 3,547 articles
« Prev 1 143 144 145 146 147 355 Next »
Advertisements