Found 4378 Articles for MySQL

How to use if clause in MySQL to display Students result as Pass or Fail in a new column?

Kumar Varma
Updated on 30-Jun-2020 13:13:00

1K+ Views

Let us first create a table −mysql> create table DemoTable    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> Name varchar(100),    -> Subject varchar(100),    -> Score int    -> ); Query OK, 0 rows affected (0.94 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(Name, Subject, Score) values('Chris', 'MySQL', 80); Query OK, 1 row affected (0.32 sec) mysql> insert into DemoTable(Name, Subject, Score) values('Robert', 'MongoDB', 45); Query OK, 1 row affected (0.62 sec) mysql> insert into DemoTable(Name, Subject, Score) values('Adam', 'Java', 78); Query OK, 1 row affected ... Read More

How to count number of NULLs in a row with MySQL?

Rama Giri
Updated on 30-Jun-2020 13:15:04

566 Views

Use ISNULL() from MySQL. Let us first create a table −mysql> create table DemoTable    -> (    -> Number1 int,    -> Number2 int    -> ); Query OK, 0 rows affected (0.59 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(10, NULL); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values(NULL, NULL); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values(29, 98); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values(NULL, 119); Query OK, 1 row affected (0.15 sec)Display all records ... Read More

Can I get the count of repeated values in a column with MySQL?

Kumar Varma
Updated on 30-Jun-2020 13:16:31

994 Views

Yes, you can use ORDER BY DESC with GROUP BY. Let us first create a table −mysql> create table DemoTable    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> PostMessage varchar(100)    -> ); Query OK, 0 rows affected (0.69 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(PostMessage) values('Hi'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable(PostMessage) values('Hello'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable(PostMessage) values('Hi'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable(PostMessage) values('Awesome'); Query OK, ... Read More

How to select return value from MySQL prepared statement?

Rama Giri
Updated on 30-Jun-2020 13:17:20

700 Views

Let us create a stored procedure and select return value from MySQL prepared statement −mysql> DELIMITER // mysql> CREATE PROCEDURE return_value()    -> BEGIN    ->   SET @returnQuery= 'SELECT 98 INTO @value';    ->   PREPARE stmt FROM @returnQuery;    ->   EXECUTE stmt;    -> END    -> // Query OK, 0 rows affected (0.20 sec) mysql> DELIMITER ;Call stored procedure using CALL command.mysql> call return_value(); Query OK, 1 row affected (0.07 sec)Display value using select statement −mysql> select @value;outputThis will produce the following output −+--------+ | @value | +--------+ |     98 | +--------+ 1 row in set (0.00 sec)

Select all rows except from today in MySQL?

Kumar Varma
Updated on 30-Jun-2020 13:19:19

405 Views

Let us first create a table −mysql> create table DemoTable    -> (    -> Name varchar(100),    -> DueDate datetime    -> ); Query OK, 0 rows affected (0.54 sec)Insert some records in the table using insert command. Let’s say the current date is “2019-07-03” −mysql> insert into DemoTable values('Chris', '2019-06-24'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('Chris', '2018-01-01'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('Robert', '2019-07-03'); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable values('Carol', '2019-08-03'); Query OK, 1 row affected (0.22 ... Read More

MySQL query to find a value appearing more than once?

Rama Giri
Updated on 30-Jun-2020 13:20:19

392 Views

Let us first create a table −mysql> create table DemoTable    -> (    -> value int    -> ); Query OK, 0 rows affected (0.82 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(10); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values(100); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values(20); Query OK, 1 row affected (0.28 sec) mysql> insert into DemoTable values(10); Query OK, 1 row affected (0.34 sec) mysql> insert into DemoTable values(30); Query OK, 1 row affected (0.24 sec) ... Read More

Create a temporary table in a MySQL procedure?

Kumar Varma
Updated on 30-Jun-2020 12:56:38

2K+ Views

To create a temporary table in a MySQL procedure, following is the syntax −CREATE PROCEDURE yourProcedureName()    BEGIN       CREATE TEMPORARY TABLE yourTemporaryTableName SELECT yourValue;    ENDLet us implement the above syntax to create a temporary table and insert some records in the table. Following is the query to create a stored procedure and a temporary table in it −mysql> DELIMITER // mysql> CREATE PROCEDURE create_Temporary_Table()    -> BEGIN    ->    CREATE TEMPORARY TABLE tmpDemoTable SELECT 500;    -> END// Query OK, 0 rows affected (0.15 sec)Following is the query to insert record in the table −mysql> ... Read More

MySQL query to search within the last 5 characters in a column?

Rama Giri
Updated on 30-Jun-2020 12:57:19

159 Views

Let us first create a table −mysql> create table DemoTable    -> (    -> EmployeeName varchar(100)    -> ); Query OK, 0 rows affected (0.81 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Adam Smith'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('Carol Taylor'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('David Miller'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable values('Chris Evan'); Query OK, 1 row affected (0.13 sec)Display all records from the table using select statement −mysql> select ... Read More

MySQL query to get the character length for all the values in a column?

Kumar Varma
Updated on 30-Jun-2020 12:58:56

170 Views

To get the character length, use the CHAR_LENGTH() method. Let us first create a table −mysql> create table DemoTable    -> (    -> Name varchar(100)    -> ); Query OK, 0 rows affected (1.04 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('John'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('Robert'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('Bob'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable values('David'); Query OK, 1 row affected (0.15 sec)Display all records from the table ... Read More

How to Order by a specific string in MySQL?

Rama Giri
Updated on 30-Jun-2020 13:00:16

266 Views

Let us first create a table −mysql> create table DemoTable    -> (    -> FirstName varchar(100)    -> ); Query OK, 0 rows affected (0.53 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('John'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('Adam'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values('Sam'); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable values('Johnny'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values('Joy'); Query OK, 1 row affected (0.12 sec) ... Read More

Advertisements