- 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
AmitDiwan has Published 11365 Articles
AmitDiwan
248 Views
To generate random numbers, use the ORDER BY RAND() function in MySQL. Let us first create a table −mysql> create table DemoTable (Value int); Query OK, 0 rows affected (0.76 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(89); Query OK, 1 row affected (0.19 ... Read More
AmitDiwan
205 Views
For this, you can use LAST_INSERT_ID(). Let us first create a table. Here, we have set the auto_increment id to StudentId column −mysql> create table DemoTable1 (StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY); Query OK, 0 rows affected (0.58 sec)Insert some records in the table using insert command −mysql> insert ... Read More
AmitDiwan
233 Views
No, MySQL sleep function is not busy-wait. Let us first create a table and implement the SLEEP() function −mysql> create table DemoTable(FirstName varchar(100)); Query OK, 0 rows affected (0.57 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('John'); Query OK, 1 row affected (0.15 sec) ... Read More
AmitDiwan
691 Views
To order by field, use CASE statement. Let us first create a table −mysql> create table DemoTable(StudentId varchar(100)); Query OK, 0 rows affected (1.69 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('STU-980'); Query OK, 1 row affected (0.28 sec) mysql> insert into DemoTable values('STU-1029'); ... Read More
AmitDiwan
732 Views
For this, use count(*) and the divide the count of two different sets of rows. Let us first create a table −mysql> create table DemoTable(isMarried tinyint(1)); Query OK, 0 rows affected (0.53 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(1); Query OK, 1 row ... Read More
AmitDiwan
631 Views
To copy all rows of a table to another table, use the below syntax −insert into yourTableName2(yourColumnName1, ...N) select yourColumnName1, ..N from yourTableName1;Let us first create a table −mysql> create table DemoTable1(FirstName varchar(100)); Query OK, 0 rows affected (1.11 sec)Insert some records in the table using insert command −mysql> insert ... Read More
AmitDiwan
365 Views
Let’s say we have two tables and both of them have two columns PlayerId and PlayerScore. We need to add the PlayerScore from both these tables, but only for a particular PlayerId.For this, you can use UNION. Let us first create a table −mysql> create table DemoTable1(PlayerId int, PlayerScore int); ... Read More
AmitDiwan
1K+ Views
Let us first create a table −mysql> create table DemoTable(DueDate datetime); Query OK, 0 rows affected (0.94 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('2019-07-10 04:20:00'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('2019-07-10 05:10:40'); Query OK, 1 row affected ... Read More
AmitDiwan
2K+ Views
For this, you can use UNION. Let us first create a table −mysql> create table DemoTable1(FirstName varchar(1000)); Query OK, 0 rows affected (1.22 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1 values('John'); Query OK, 1 row affected (0.20 sec)Display all records from the table using ... Read More
AmitDiwan
1K+ Views
To check an empty table is in a database, you need to extract some records from the table. If the table is not empty then the table records would be returned.Let us first create a table −mysql> create table DemoTable(Id int, Name varchar(100), Age int); Query OK, 0 rows affected ... Read More