- 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
319 Views
For this, you can use the concept of user defined variable. Let us first create a table −mysql> create table DemoTable1868 ( Value int ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1868 values(10); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1868 values(20); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1868 values(30); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1868 values(40); Query OK, 1 row affected (0.00 sec)Display all records from the table using ... Read More
241 Views
To list all variables initialized by SET operator, the syntax is as follows −select * from performance_schema.user_variables_by_thread;Here is the query to set the variable −mysql> set @FirstName='John'; Query OK, 0 rows affected (0.00 sec) mysql> set @LastName='Doe'; Query OK, 0 rows affected (0.00 sec)Here is the query to display the list of all variables initialized by SET operator. This list includes the variables set above −mysql> select * from performance_schema.user_variables_by_thread;This will produce the following output −+-----------+---------------+----------------+ | THREAD_ID | VARIABLE_NAME | VARIABLE_VALUE | +-----------+---------------+----------------+ | 120 | TotalAmount | 5000 | ... Read More
459 Views
For this, use date_add() with interval command. Let us first create a table −mysql> create table DemoTable1867 ( ArrivalTime datetime ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1867 values('2019-10-12 12:34:45'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1867 values('2019-10-12 10:04:15'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1867 values('2019-10-12 11:00:23'); Query OK, 1 row affected (0.00 sec)Display all records from the table using select statement −mysql> select * from DemoTable1867; This will produce the following output ... Read More
258 Views
For this, use FIND_IN_SET(). Let us first create a table −mysql> create table DemoTable1866 ( Value1 int, ListOfValues varchar(100) ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1866 values(56, '78, 56, 98, 95'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1866 values(103, '103, 90, 102, 104'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1866 values(77, '34, 45, 77, 78'); Query OK, 1 row affected (0.00 sec)Display all records from the table using select statement −mysql> ... Read More
435 Views
To round, use MySQL ROUND() function. Let us first create a table −mysql> create table DemoTable1865 ( Value1 int, Value2 int ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1865 values(40, 60); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1865 values(100, 400); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1865 values(545, 896); Query OK, 1 row affected (0.00 sec)Display all records from the table using select statement −mysql> select * from DemoTable1865;This will produce the ... Read More
849 Views
Use @anyVariableName to assign the result of a query into a variable. Let us first create a table −mysql> create table DemoTable1864 ( Id int, FirstName varchar(20), LastName varchar(20) ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1864 values(101, 'Chris', 'Brown'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1864 values(102, 'David', 'Miller'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1864 values(103, 'Adam', 'Smith'); Query OK, 1 row affected (0.00 sec) mysql> insert into ... Read More
553 Views
To set default value for empty row, use the concept of COALESCE(). Let us first create a table −mysql> create table DemoTable1863 ( FirstName varchar(20) ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1863 values('Chris'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1863 values(NULL); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1863 values('David'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1863 values(NULL); Query OK, 1 row affected (0.00 sec)Display all records from the table ... Read More
151 Views
For this, use the concept of GREATEST(). Let us first create a table −mysql> create table DemoTable1862 ( Value1 int, Value2 int, Value3 int, Value4 int ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1862 values(43, 34, 56, 42); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1862 values(NULL, 78, 65, NULL); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1862 values(110, NULL, 78, NULL); Query OK, 1 row affected (0.00 sec)Display all ... Read More
351 Views
For this, you can use GROUP BY HAVING with subquery. Let us first create a table −mysql> create table DemoTable1861 ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, Name varchar(20), Marks int ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1861(Name, Marks) values('John', 45); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1861(Name, Marks) values('Chris', 74); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1861(Name, Marks) values('David', 89); Query OK, 1 row affected (0.00 sec) ... Read More
430 Views
For this, you can use SELECT INTO. Let us first create a table −mysql> create table DemoTable1860 ( Amount int ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1860 values(1590); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1860 values(410); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1860 values(3000); Query OK, 1 row affected (0.00 sec)Display all records from the table using select statement −Mysql> select * from DemoTable1860; This will produce the following output −+--------+ | Amount ... Read More