Found 4219 Articles for MySQLi

Sort data for duplicate record in MySQL

AmitDiwan
Updated on 09-Sep-2019 08:37:00

416 Views

Use ORDER BY to sort data for duplicate record.Let us first create a table −mysql> create table DemoTable788 ( FirstName varchar(100), Score int ); Query OK, 0 rows affected (1.89 sec)Insert some records in the table using insert command −mysql> insert into DemoTable788 values('Chris', 78); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable788 values('Robert', 67); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable788 values('Chris', 98); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable788 values('Chris', 56); Query OK, 1 row affected (0.15 sec) mysql> insert into ... Read More

Select a specific value between two column values in MySQL?

AmitDiwan
Updated on 09-Sep-2019 08:35:21

2K+ Views

Let us first create a table −mysql> create table DemoTable787 ( Score1 int, Score2 int, Name varchar(100) ); Query OK, 0 rows affected (0.84 sec)Insert some records in the table using insert command −mysql> insert into DemoTable787 values(34, 56, 'Chris'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable787 values(73, 86, 'Robert'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable787 values(90, 99, 'David'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable787 values(80, 89, 'Adam'); Query OK, 1 row affected (0.21 sec)Display all records ... Read More

How to display column values as CSV in MySQL?

AmitDiwan
Updated on 09-Sep-2019 08:33:31

510 Views

To display column values as CSV, use GROUP_CONCAT().Let us first create a table −mysql> create table DemoTable786 (    StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    StudentName varchar(100) )   AUTO_INCREMENT=101; Query OK, 0 rows affected (0.70 sec)Insert some records in the table using insert command −mysql> insert into DemoTable786(StudentName) values('Chris'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable786(StudentName) values('Robert'); Query OK, 1 row affected (0.24 sec) mysql> insert into DemoTable786(StudentName) values('Mike'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable786(StudentName) values('Sam'); Query OK, 1 row affected (0.12 sec)Display all records from the table ... Read More

How can I select rows which fall on a specific day of week in MySQL?

AmitDiwan
Updated on 09-Sep-2019 08:31:15

127 Views

For specific day of week, use DAYOFWEEK().Let us first create a table −mysql> create table DemoTable785 ( CustomerId int NOT NULL AUTO_INCREMENT PRIMARY KEY, CustomerName varchar(100), ShoppingDate date ); Query OK, 0 rows affected (0.61 sec)Insert some records in the table using insert command −mysql> insert into DemoTable785(CustomerName, ShoppingDate) values('Chris', '2019-07-03'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable785(CustomerName, ShoppingDate) values('Robert', '2019-07-01'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable785(CustomerName, ShoppingDate) values('David', '2019-07-06'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable785(CustomerName, ShoppingDate) ... Read More

MySQL query to sort column values and ignoring quotes on one of the values

AmitDiwan
Updated on 09-Sep-2019 08:16:48

149 Views

To ignore quotes while ordering column values, use ORDER BY TRIM().Let us first create a table −mysql> create table DemoTable784 ( Message varchar(100) ); Query OK, 0 rows affected (0.50 sec)Insert some records in the table using insert command −mysql> insert into DemoTable784 values('Good'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable784 values('\"This is not a Message\"'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable784 values('Bye'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable784 values('Hello'); Query OK, 1 row affected (0.15 sec)Display all records from the table using ... Read More

Count and sort rows with a single MySQL query

AmitDiwan
Updated on 09-Sep-2019 08:14:30

136 Views

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

MySQL query to group by column and display the sum of similar values in another column

AmitDiwan
Updated on 09-Sep-2019 08:12:49

427 Views

For this, use GROUP BY HAVING clause.Let us first create a table −mysql> create table DemoTable782 ( Name varchar(100), Score int ); Query OK, 0 rows affected (1.18 sec)Insert some records in the table using insert command −mysql> insert into DemoTable782 values('John', 156); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable782 values('Carol', 250); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable782 values('Bob', 140); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable782 values('John', 126); Query OK, 1 row affected (0.29 sec) mysql> insert into DemoTable782 values('John', ... Read More

Find the count of EMPTY or NULL columns in a MySQL table?

AmitDiwan
Updated on 09-Sep-2019 08:10:53

980 Views

Let us first create a table −mysql> create table DemoTable781 ( Name varchar(100) ); Query OK, 0 rows affected (0.66 sec)Insert some records in the table using insert command −mysql> insert into DemoTable781 values(''); Query OK, 1 row affected (0.29 sec) mysql> insert into DemoTable781 values('Chris'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable781 values(''); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable781 values(null); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable781 values(null); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable781 values(''); Query OK, 1 ... Read More

How to display the column names from a table excluding some in MySQL?

AmitDiwan
Updated on 09-Sep-2019 08:09:06

316 Views

To exclude some of the column names, use NOT IN.Let us first create a table −mysql> create table DemoTable780 (    CustomerId int,    CustomerName varchar(100),    CustomerAge int, CustomerCountryName varchar(100), isMarried tinyint(1) ); Query OK, 0 rows affected (0.47 sec)Here is the query to exclude result −mysql> select group_concat(column_name) from `information_schema`.`COLUMNS` m where table_schema = 'web' and table_name = 'DemoTable780' and column_name not in ('CustomerId','CustomerCountryName') group by table_schema,table_name;This will produce the following output -+------------------------------------+ | group_concat(column_name) | +------------------------------------+ | CustomerName,CustomerAge,isMarried | +------------------------------------+ 1 row in set (0.01 sec)

Increment column value ‘ADD’ with MySQL SET clause

AmitDiwan
Updated on 09-Sep-2019 08:06:27

134 Views

Since the column value ‘ADD’ is already a reserved word, therefore you need to use backticks around the word ADD like `ADD`.Let us see an example and create a table −mysql> create table DemoTable779 ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, `ADD` int ); Query OK, 0 rows affected (0.47 sec)Insert some records in the table using insert command −mysql> insert into DemoTable779(`ADD`) values(54); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable779(`ADD`) values(89); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable779(`ADD`) values(66); Query OK, 1 row affected ... Read More

Advertisements