
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 4381 Articles for MySQL

739 Views
To set conditions, use CASE WHEN statement in MySQL. Let us first create a table −mysql> create table DemoTable -> ( -> Value1 int, -> Value2 int, -> Value3 int, -> Value4 int -> ); Query OK, 0 rows affected (0.98 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(1, 0, 1, 1); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable values(1, 0, 1, 0); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values(1, 1, 1, 1); Query OK, 1 row affected (0.20 ... Read More

337 Views
To set conditions while adding column values, use MySQL IF(). Let us first create a table −mysql> create table DemoTable -> ( -> Value1 int, -> Value2 int, -> Value3 int -> ); Query OK, 0 rows affected (0.64 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(10, 20, -30); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable values(50, 60, 90); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values(100, 200, 400); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable values(30, ... Read More

1K+ Views
The group is a reserved keyword, you can’t use it as table name. Therefore, on using it as table name would lead to an error. To avoid such error, you need to use enclosed backticks symbol around the table name ‘group’.Let us now see an example and create a table −mysql> create table `group` -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> Name varchar(20) -> ); Query OK, 0 rows affected (1.26 sec)Insert some records in the table using insert command −mysql> insert into `group`(Name) values('Chris'); Query OK, 1 row affected (0.47 sec) ... Read More

437 Views
Let’s say, here I am using the WEB database. We need to find the number of tables in the database WEB. For this, use the INFORMATION_SCHEMA.TABLES in MySQL.Following is the query to display the number of tables −mysql> select count(table_name) as TotalNumberOfTablesInWebDatabase -> from information_schema.tables -> where table_schema='web';This will produce the following output −+----------------------------------+ | TotalNumberOfTablesInWebDatabase | +----------------------------------+ | 1562 | +----------------------------------+ 1 row in set (0.27 sec)To just check whether the count of records displayed above are the same or not, use the ... Read More

195 Views
You can use ORDER BY STR_TO_DATE(). Let us first create a table −mysql> create table DemoTable -> ( -> DueTime varchar(20) -> ); Query OK, 0 rows affected (0.87 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('7:30AM'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('9:00PM'); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable values('11:00PM'); Query OK, 1 row affected (0.13 sec)Display all records from the table using select statement −mysql> select * from DemoTable;This will produce the following output−+---------+ | DueTime | +---------+ | ... Read More

214 Views
To round number, use MySQL ROUND(). Let us first create a table −mysql> create table DemoTable -> ( -> Amount DECIMAL(10, 4) -> ); Query OK, 0 rows affected (1.18 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(100.578); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values(1000.458); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values(980.89); Query OK, 1 row affected (0.13 sec)Display all records from the table using select statement −mysql> select * from DemoTable;This will produce the following output−+-----------+ | Amount | ... Read More

327 Views
Let us first create a table −mysql> create table DemoTable -> ( -> UserName varchar(20), -> UserType ENUM('New User', 'Registered User') -> ); Query OK, 0 rows affected (0.60 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Chris', 'New User'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('David', 'New User'); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable values('Mike', 'Registered User'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable values('Sam', 'New User'); Query OK, 1 row affected (0.10 sec)Display all records ... Read More

629 Views
To sum, use the aggregate function SUM(). With that, group using MySQL GROUP BY. Let us first create a table −mysql> create table DemoTable -> ( -> ProductName varchar(20), -> ProductQuantity int, -> ProductPrice int -> ); Query OK, 0 rows affected (0.63 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Product-1', 2, 50); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values('Product-2', 3, 80); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values('Product-2', 4, 100); Query OK, 1 row affected (0.11 sec) mysql> ... Read More

319 Views
Yes, we can set a single value with IN() in MySQL. Let us first create a table−mysql> create table DemoTable -> ( -> FirstName varchar(20) -> ); Query OK, 0 rows affected (0.65 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Chris'); Query OK, 1 row affected (0.42 sec) mysql> insert into DemoTable values('David'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('Mike'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values('Bob'); Query OK, 1 row affected (0.08 sec)Display all records from the table using select ... Read More

290 Views
Yes, we can change the order of columns. This can be done using ALTER command and AFTER to set the new order of an individual column. Let us first create a table −mysql> create table DemoTable -> ( -> `Student_Key_Age` int, -> `Student_Key_Name` varchar(20), -> `Student_Key_CountryName` varchar(20) -> ); Query OK, 0 rows affected (0.64 sec)Following is the query to alter order of columns −mysql> alter table DemoTable modify column `Student_Key_Age` int after `Student_Key_Name`; Query OK, 0 rows affected (1.15 sec) Records: 0 Duplicates: 0 Warnings: 0Let us check the table description once again −mysql> ... Read More