- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- 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 6702 Articles for Database
2K+ Views
For this, you can use the CASE statement. Let us first create a table−mysql> create table DemoTable -> ( -> Name varchar(20), -> Marks1 int, -> Marks2 int -> ); Query OK, 0 rows affected (0.72 sec)Insert some records in the table using insert command−mysql> insert into DemoTable values('Chris', 45, null); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('David', null, 78); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values('Bob', 67, 98); Query OK, 1 row affected (0.14 sec)Display all records from the table using select statement −mysql> ... Read More
73 Views
For this, use MySQL FIND_IN_SET(). Let us first create a table −mysql> create table DemoTable1563 -> ( -> StudentId int, -> StudentName varchar(20) -> ); Query OK, 0 rows affected (0.52 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1563 values(1001, 'Chris'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable1563 values(1010, 'Bob'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable1563 values(1005, 'Chris'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable1563 values(1015, 'David'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable1563 ... Read More
665 Views
To sort from max to min value, use ORDER BY length(). Let us first create a table −mysql> create table DemoTable -> ( -> Price varchar(20) -> ); Query OK, 0 rows affected (0.92 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('80'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('800'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values('108'); Query OK, 1 row affected (0.50 sec) mysql> insert into DemoTable values('765'); Query OK, 1 row affected (0.14 sec)Display all records from the table using ... Read More
255 Views
Do not prefix table name with field name like user_name. Instead, use user or username.If you prefix table name, then there may be a chance of ambiguity, so avoid prefixing table name.Let us first create a table −mysql> create table user -> ( -> username varchar(20), -> password varchar(20) -> ); Query OK, 0 rows affected (0.66 sec)Insert some records in the table using insert command −mysql> insert into user values('John', 'J_635'); Query OK, 1 row affected (0.34 sec) mysql> insert into user values('Carol', 'Carol2212'); Query OK, 1 row affected (0.16 sec) mysql> insert into user ... Read More
80 Views
For this, use MySQL MONTH() and YEAR() methods. Let us first create a table −mysql> create table DemoTable1562 -> ( -> VoucherValue int, -> RechargeDate date -> ); Query OK, 0 rows affected (1.40 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1562 values(149, '2019-10-21'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable1562 values(199, '2019-10-13'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable1562 values(399, '2018-10-13'); Query OK, 1 row affected (0.25 sec) mysql> insert into DemoTable1562 values(450, '2019-10-13'); Query OK, 1 row affected (0.20 sec)Display all ... Read More
125 Views
For this, you can use a sub query along with MIN(). Let us first create a table−mysql> create table DemoTable -> ( -> Name varchar(20), -> Score int -> ); Query OK, 0 rows affected (0.56 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('John', 56); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values('John', 45); Query OK, 1 row affected (0.24 sec) mysql> insert into DemoTable values('John', 58); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values('Chris', 43); Query OK, 1 row affected (0.15 ... Read More
77 Views
For this, you can use GROUP_CONCAT(). Let us first create a table −mysql> create table DemoTable1561 -> ( -> StudentName varchar(20), -> Title text -> ); Query OK, 0 rows affected (0.60 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1561 values('Adam', 'Learning Java'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable1561 values('Bob', 'Learning C'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable1561 values('Adam', 'Learning Spring and Hibernate Framework'); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable1561 values('Carol', 'Learning MySQL from basic'); Query ... Read More
67 Views
For same results, do not use ! operator. The NOT keyword is already provided by MySQL. Let us first create a table −mysql> create table DemoTable1560 -> ( -> Value1 int -> ); Query OK, 0 rows affected (0.50 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1560 values(0); Query OK, 1 row affected (0.16 sec)Display all records from the table using select statement −mysql> select * from DemoTable1560;This will produce the following output −+--------+ | Value1 | +--------+ | 0 | +--------+ 1 row in set (0.00 sec)Here is the ... Read More
685 Views
You can’t use the index as a column name because it is a reserved word. For this, you need to use backticks around the column name.If you will use a reserved word as the column name, you can see the following error−mysql> create table DemoTable -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> index int -> )ENGINE=MyISAM; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'int )ENGINE=MyISAM' at line 4Let us first ... Read More
374 Views
To order results of a query randomly, use ORDER BY RAND(). The syntax is as follows −select * from DemoTable1559 where yourColumnName IN(yourValue1, yourValue2, ....N) order by rand() limit yourLimitValue;Let us first create a table −mysql> create table DemoTable1559 -> ( -> EmployeeId int, -> EmployeeName varchar(20), -> EmployeeAge int -> ); Query OK, 0 rows affected (1.22 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1559 values(101, 'Bob', 28); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable1559 values(102, 'Robert', 26); Query OK, 1 row affected (0.16 sec) ... Read More