AmitDiwan has Published 10740 Articles

How to display only the column values whose sum is less than 150 in MySQL? Arrange the result in descending order

AmitDiwan

AmitDiwan

Updated on 03-Sep-2019 11:39:54

182 Views

For this, you can use subquery. Let us first create a table −mysql> create table DemoTable844(    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    Amount int ); Query OK, 0 rows affected (0.95 sec)Insert some records in the table using insert command −mysql> insert into DemoTable844(Amount) values(80); Query OK, ... Read More

Set value only for NULL values in a MySQL table

AmitDiwan

AmitDiwan

Updated on 03-Sep-2019 11:38:27

200 Views

Use IFNULL to check for NULL values and set a value using the SET command. Let us first create a table −mysql> create table DemoTable817(Value int); Query OK, 0 rows affected (0.53 sec)Insert some records in the table using insert command −mysql> insert into DemoTable817 values(10); Query OK, 1 row ... Read More

Display all grants for user in MySQL

AmitDiwan

AmitDiwan

Updated on 03-Sep-2019 11:34:00

252 Views

Use INFORMATION_SCHEMA.SCHEMA_PRIVILEGES to display all grants for a user −select *from INFORMATION_SCHEMA.SCHEMA_PRIVILEGES;Let us implement the above syntax to show all grants for a user −mysql> select *from INFORMATION_SCHEMA.SCHEMA_PRIVILEGES;This will produce the following output −+-----------------------------+---------------+--------------------+-------------------------+--------------+ | GRANTEE                     | TABLE_CATALOG | TABLE_SCHEMA ... Read More

Set particular value of column without using update and while inserting values in MySQL

AmitDiwan

AmitDiwan

Updated on 03-Sep-2019 11:18:32

223 Views

Here, we will see an example wherein we are inserting dates and updating them while using the INSERT query.Let us first create a table −mysql> create table DemoTable816(DueDate datetime); Query OK, 0 rows affected (0.45 sec)Insert some records in the table using the insert command. Here is the query to ... Read More

Extract gender values as a string when it is stored in the table as a Boolean in MySQL

AmitDiwan

AmitDiwan

Updated on 03-Sep-2019 11:16:28

468 Views

Let us first create a table −mysql> create table DemoTable815(Gender BOOLEAN); Query OK, 0 rows affected (0.84 sec)Insert some records in the table using insert command −mysql> insert into DemoTable815 values(true); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable815 values(false); Query OK, 1 row affected (0.16 sec) ... Read More

Add 30 days to date in a MySQL table with arrival date records

AmitDiwan

AmitDiwan

Updated on 03-Sep-2019 11:12:00

322 Views

Use INTERVAL to update the days for all the dates in a MySQL table column. Let us first create a table −mysql> create table DemoTable814(ArrivalDate date); Query OK, 0 rows affected (0.58 sec)Insert some records in the table using insert command −mysql> insert into DemoTable814 values('2018-12-02'); Query OK, 1 row ... Read More

Group concatenate the last name from a MySQL column and set a condition to display limited records

AmitDiwan

AmitDiwan

Updated on 03-Sep-2019 11:04:18

103 Views

Use GROUP_CONCAT() to perform group concatenation and set a condition. Let us first create a table −mysql> create table DemoTable813(    UserId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    UserFirstName varchar(100),    UserLastName varchar(100) ); Query OK, 0 rows affected (0.49 sec)Insert some records in the table using insert command ... Read More

How to use MySQL LIKE to create a search system and display results on the basis of keyword?

AmitDiwan

AmitDiwan

Updated on 03-Sep-2019 11:01:26

171 Views

To display results on the basis of keyword, use the LIKE operator as in the following syntax −select *from yourTableName where yourColumnName LIKE '%yourValue%';Let us first create a table −mysql> create table DemoTable812(Comments text); Query OK, 0 rows affected (0.61 sec)Insert some records in the table using insert command −mysql> ... Read More

Is INNODB enabled by default in MySQL?

AmitDiwan

AmitDiwan

Updated on 03-Sep-2019 11:00:23

179 Views

Yes, it is enabled by default from MySQL version 4.0. Here, we are using MySQL version 8.0.1 −mysql> select version(); +-----------+ | version() | +-----------+ | 8.0.12    | +-----------+ 1 row in set (0.00 sec)Let us now check the my.ini wherein the default engine type InnoDB is visible ... Read More

Can I insert two or more rows in a MySQL table at once?

AmitDiwan

AmitDiwan

Updated on 03-Sep-2019 10:57:22

136 Views

Yes, we can insert two or more rows in a table at once. Following is the syntax −insert into yourTableName(yourColumnName1, yourColumnName2) values(yourValue1, yourValue2), (yourValue1, yourValue2), .........N;Let us first create a table −mysql> create table DemoTable811(    StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    StudentName varchar(100),    StudentAge int ); ... Read More

Advertisements