Found 4219 Articles for MySQLi

How to get total occurrences of a value within its own MySQL query?

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

143 Views

For this, you can use subquery. Let us first create a table −mysql> create table DemoTable    -> (    -> Value int    -> ); Query OK, 0 rows affected (0.61 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(20); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable values(30); Query OK, 1 row affected (0.36 sec) mysql> insert into DemoTable values(20); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values(40); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values(30); Query OK, ... Read More

Get the number of rows in a particular table with MySQL

Rama Giri
Updated on 30-Jun-2020 13:30:38

112 Views

Let us first create a table −mysql> create table DemoTable    -> (    -> LastName varchar(100)    -> ); Query OK, 0 rows affected (0.68 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Smith'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('Miller'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('Taylor'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('Brown'); Query OK, 1 row affected (0.29 sec)Display all records from the table using select statement −mysql> select *from DemoTable;OutputThis will produce ... Read More

Query MySQL with unicode char code?

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

345 Views

Let us first create a table −mysql> create table DemoTable    -> (    -> Value int    -> ); Query OK, 0 rows affected (0.57 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(0x41); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values(0x30); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values(0x61); Query OK, 1 row affected (0.27 sec)Display all records from the table using select statement −mysql> select *from DemoTable;OutputThis will produce the following output −+-------+ | Value | +-------+ |    65 | | ... Read More

How to get the seed value of an identity column in MySQL?

Rama Giri
Updated on 30-Jun-2020 13:09:13

477 Views

For this, you can use SHOW VARIABLES command −mysql> SHOW VARIABLES LIKE 'auto_inc%';OutputThis will produce the following output −+--------------------------+-------+ | Variable_name            | Value | +--------------------------+-------+ | auto_increment_increment | 1     | | auto_increment_offset    | 1     | +--------------------------+-------+ 2 rows in set (0.95 sec)You can control over AUTO_INCREMENT outside.Let us first create a table −mysql> create table DemoTable    -> (    -> StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY    -> ); Query OK, 0 rows affected (0.94 sec)Insert some records in the table using insert command −mysql> insert into DemoTable ... Read More

Select the topmost record from a table ordered by desc on the basis of ID?

Kumar Varma
Updated on 30-Jun-2020 13:10:20

44 Views

For this, use ORDER BY DESC with LIMIT 1. Let us first create table −mysql> create table DemoTable    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> UserName varchar(100),    -> UserMessage text    -> ); Query OK, 0 rows affected (1.17 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(UserName, UserMessage) values('Adam', 'Hi'); Query OK, 1 row affected (0.92 sec) mysql> insert into DemoTable(UserName, UserMessage) values('Chris', 'Awesome'); Query OK, 1 row affected (0.52 sec) mysql> insert into DemoTable(UserName, UserMessage) values('Robert', 'Nice'); Query OK, 1 row affected (0.65 sec) ... Read More

Display records ignoring NULL in MySQL

Rama Giri
Updated on 30-Jun-2020 13:11:10

106 Views

Use IS NOT NULL to display only NOT NULL records. Let us first create a table −mysql> create table DemoTable    -> (    -> FirstName varchar(100)    -> ); Query OK, 0 rows affected (3.01 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('John'); Query OK, 1 row affected (0.44 sec) mysql> insert into DemoTable values(NULL); Query OK, 1 row affected (0.58 sec) mysql> insert into DemoTable values('Chris'); Query OK, 1 row affected (0.31 sec) mysql> insert into DemoTable values(NULL); Query OK, 1 row affected (0.20 sec) mysql> insert into ... Read More

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

995 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)

Advertisements