MySQLi Articles

Page 299 of 341

How to check if data is NULL in MySQL?

Samual Sam
Samual Sam
Updated on 30-Jul-2019 469 Views

You can use IF() to check if data is NULL.  Let us first create a table −mysql> create table DemoTable (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    Name varchar(200),    Age int ); Query OK, 0 rows affected (0.44 sec)Insert records in the table using insert command −mysql> insert into DemoTable(Name, Age) values('John', 23); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable(Name, Age) values('Sam', null); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable(Name, Age) values('Mike', 23); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable(Name, Age) values('David', 21); Query OK, ...

Read More

How to display message from a stored procedure?

karthikeya Boyini
karthikeya Boyini
Updated on 30-Jul-2019 6K+ Views

To display message from stored procedure on the basis of conditions, let us use IF-ELSE condition −mysql> DELIMITER // mysql> CREATE PROCEDURE showMessage(value int, Name varchar(20))    BEGIN       IF(value > 100) then          SELECT CONCAT("HELLO", " ", Name);       ELSE          SELECT CONCAT("BYE", " ", Name);       END IF;       END       // Query OK, 0 rows affected (0.18 sec) mysql> DELIMITER ;Case 1 − Call the stored procedure using CALL command, when value is more than 100 −call showMessage(200, 'John');This will produce ...

Read More

MySQL query to perform delete operation where id is the biggest?

Samual Sam
Samual Sam
Updated on 30-Jul-2019 232 Views

You can use ORDER BY DESC command with LIMIT 1 for this since we need to delete only a single ID.Let us first create a table −mysql> create table DemoTable (    UserId int,    UserName varchar(20) ); Query OK, 0 rows affected (0.57 sec)Insert records in the table using insert command −mysql> insert into DemoTable values(100, 'John'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values(234, 'Mike'); Query OK, 1 row affected (0.28 sec) mysql> insert into DemoTable values(145, 'Sam'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values(278, 'Carol'); Query OK, 1 ...

Read More

MySQL query to select too many rows?

karthikeya Boyini
karthikeya Boyini
Updated on 30-Jul-2019 529 Views

You can use LIMIT for this, which is used to fetch limited number of records. Let us first create a table −mysql> create table DemoTable (    Id int,    Name varchar(20) ); Query OK, 0 rows affected (0.53 sec)Insert records in the table using insert command −mysql> insert into DemoTable values(10, 'John'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values(11, 'Chris'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values(12, 'David'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values(13, 'Carol'); Query OK, 1 row affected (0.13 sec) mysql> ...

Read More

Which datatype is should I use to set a column for 5-star rating?

Samual Sam
Samual Sam
Updated on 30-Jul-2019 775 Views

You can use ENUM datatype for this. Let us first create a table −mysql> create table DemoTable (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    UserRating ENUM('1', '2', '3', '4', '5') ); Query OK, 0 rows affected (0.54 sec)Insert records in the table using insert command −mysql> insert into DemoTable(UserRating) values('5'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable(UserRating) values('3'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable(UserRating) values('1'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable(UserRating) values('3'); Query OK, 1 row affected (0.24 sec) mysql> insert into DemoTable(UserRating) values('4'); ...

Read More

Replace dot with comma on MySQL SELECT?

karthikeya Boyini
karthikeya Boyini
Updated on 30-Jul-2019 6K+ Views

To replace dot with comma on SELECT, you can use REPLACE(). Following is the syntax −select replace(yourColumnName, '.' , ', ' ) from yourTableName;Let us first create a table −mysql> create table DemoTable (    Value float ); Query OK, 0 rows affected (0.63 sec)Insert records in the table using insert command −mysql> insert into DemoTable values(4.56); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values(456.23); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values(1078.3); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable values(2000.50); Query OK, 1 row affected (0.26 sec) mysql> ...

Read More

How to select from a set of integers in MySQL?

Samual Sam
Samual Sam
Updated on 30-Jul-2019 266 Views

To select from a set of integers, you can use UNION. Following is the syntax −SELECT yourValue1 UNION SELECT yourValue2 UNION SELECT yourValue3 UNION SELECT yourValue4 . . . . NLet us implement the above syntax to select from a set of integers in MySQL −mysql> SELECT 1000 UNION SELECT 2000 UNION SELECT 3000 UNION SELECT 4000 UNION SELECT 5000 UNION SELECT 6000 UNION SELECT 7000;This will produce the following output −+------+ | 1000 | +------+ | 1000 | | 2000 | | 3000 | | 4000 | | 5000 | | 6000 | | 7000 | +------+ 7 rows in set (0.03 sec)

Read More

How to remove Duplicate Records except a single record in MySQL?

karthikeya Boyini
karthikeya Boyini
Updated on 30-Jul-2019 1K+ Views

You can use DELETE command with some condition for this since we need to keep one record and delete rest of the duplicate records.Let us first create a table −mysql> create table DemoTable (    StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    StudentName varchar(40) ); Query OK, 0 rows affected (0.48 sec)Insert records in the table using insert command −mysql> insert into DemoTable(StudentName) values('John'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable(StudentName) values('Carol'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable(StudentName) values('Sam'); Query OK, 1 row affected (0.28 sec) mysql> insert into DemoTable(StudentName) ...

Read More

MySQL order by from highest to lowest value?

Samual Sam
Samual Sam
Updated on 30-Jul-2019 3K+ Views

To order by from highest to lowest value, you can use ORDER BY DESC command −select *from yourTableName order by yourColumnName DESC;If you want the result from lowest to highest, you can use ORDER BY ASC command −select *from yourTableName order by yourColumnName ASC;Let us first create a table −mysql> create table DemoTable (    Value int ); Query OK, 0 rows affected (0.56 sec)Insert records in the table using insert command −mysql> insert into DemoTable values(134); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable values(245); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable ...

Read More

Set MySQL int column to auto increment by 1 beginning at 10000?

karthikeya Boyini
karthikeya Boyini
Updated on 30-Jul-2019 671 Views

Let us first create a table. Here, we have set UserId as AUTO_INCREMENT PRIMARY KEY −mysql> create table DemoTable (    UserId int NOT NULL AUTO_INCREMENT PRIMARY KEY ); Query OK, 0 rows affected (0.72 sec)Following is the query to set int column to auto increment by 1 beginning at 10000 −mysql> alter table DemoTable AUTO_INCREMENT=10000; Query OK, 0 rows affected (0.31 sec) Records: 0 Duplicates: 0 Warnings: 0Insert records in the table using insert command −mysql> insert into DemoTable values(); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values(); Query OK, 1 row affected (0.19 sec) ...

Read More
Showing 2981–2990 of 3,404 articles
« Prev 1 297 298 299 300 301 341 Next »
Advertisements