- 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
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
386 Views
Use ORDER BY clause for this. Let us first create a table −mysql> create table DemoTable ( Value1 int, Value2 int ); Query OK, 0 rows affected (0.54 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(10, 40); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable values(50, 5); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values(51, 56); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values(52, 78); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values(90, 7); Query ... Read More
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
858 Views
For this, use the CASE statement. Let us first create a table −mysql> create table DemoTable ( Number int ); Query OK, 0 rows affected (0.83 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(10); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values(0); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values(20); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values(50); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable values(0); Query OK, 1 row affected (0.09 sec) mysql> insert ... Read More
![Smita Kapse](https://www.tutorialspoint.com/assets/profiles/13597/profile/60_103706-1512718957.jpg)
795 Views
To calculate timestamp difference, use aggregate framework. Let us first create a collection with documents −> db.timestampDifferenceDemo.insertOne({ "MovieBeginningTime": new ISODate("2019-05-12 10:20:30"), "MovieEndingTime":new ISODate("2019-05-12 12:30:20") }); { "acknowledged" : true, "insertedId" : ObjectId("5cd7ba1f6d78f205348bc644") } > db.timestampDifferenceDemo.insertOne({ "MovieBeginningTime": new ISODate("2019-05-12 04:00:00"), "MovieEndingTime":new ISODate("2019-05-12 07:10:00") }); { "acknowledged" : true, "insertedId" : ObjectId("5cd7ba3b6d78f205348bc645") }Following is the query to display all documents from a collection with the help of find() method −> db.timestampDifferenceDemo.find().pretty();This will produce the following output −{ "_id" : ObjectId("5cd7ba1f6d78f205348bc644"), "MovieBeginningTime" : ISODate("2019-05-12T10:20:30Z"), "MovieEndingTime" : ISODate("2019-05-12T12:30:20Z") } { "_id" : ... Read More
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
184 Views
Yes, we can do that. Let us first create a table −mysql> create table DemoTable ( ID int, GameScore int ); Query OK, 0 rows affected (0.55 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(15, 848747); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values(13, 909049); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values(34, 98474646); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values(31, 948474); Query OK, 1 row affected (0.27 sec)Display all records from the table using select statement ... Read More
![Anvi Jain](https://www.tutorialspoint.com/assets/profiles/13591/profile/60_98631-1512716973.jpg)
59 Views
Yes, you can use the findOne(). Following is the syntax −db.yourCollectionName.findOne();You can use toArray() as well −db.yourCollectionName.find().toArray();Let us first create a collection with documents −> db.betterFormatDemo.insertOne({"StudentName":"Adam Smith", "StudentScores":[98, 67, 89]}); { "acknowledged" : true, "insertedId" : ObjectId("5cd7ab826d78f205348bc640") } > db.betterFormatDemo.insertOne({"StudentName":"John Doe", "StudentScores":[67, 89, 56]}); { "acknowledged" : true, "insertedId" : ObjectId("5cd7ab936d78f205348bc641") } > db.betterFormatDemo.insertOne({"StudentName":"Sam Williams", "StudentScores":[45, 43, 33]}); { "acknowledged" : true, "insertedId" : ObjectId("5cd7aba76d78f205348bc642") }Following is the query to display all documents from a collection with the help of find() method −> db.betterFormatDemo.find();This will produce the following output −{ "_id" : ObjectId("5cd7ab826d78f205348bc640"), "StudentName" ... Read More
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
2K+ Views
The word order is a reserved order in MySQL and you have used it in the query. To get rid of the syntax error, you need to use backticks(` `) around the order.The correct syntax is as follows −select *from yourTableName ORDER BY `order` DESC;Let us first create a table −mysql> create table DemoTable ( `order` int ); Query OK, 0 rows affected (0.58 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(89); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values(67); Query OK, 1 row affected (0.13 sec) ... Read More
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
93 Views
For this, use both GROUP BY and ORDER BY clause. Let us first create a table −mysql> create table DemoTable ( StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, StudentGrade char(1) ); Query OK, 0 rows affected (0.87 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(StudentGrade) values('A'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable(StudentGrade) values('F'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable(StudentGrade) values('C'); Query OK, 1 row affected (0.28 sec) mysql> insert into DemoTable(StudentGrade) values('A'); Query OK, 1 row affected (0.23 sec) mysql> insert ... Read More
![Nishtha Thakur](https://www.tutorialspoint.com/assets/profiles/13598/profile/60_104893-1512719058.jpg)
640 Views
Let us first create a collection with documents −>db.decrementingOperationDemo.insertOne({"ProductName":"Product-1", "ProductPrice":756}); { "acknowledged" : true, "insertedId" : ObjectId("5cd7a8ae6d78f205348bc63c") } >db.decrementingOperationDemo.insertOne({"ProductName":"Product-2", "ProductPrice":890}); { "acknowledged" : true, "insertedId" : ObjectId("5cd7a8b86d78f205348bc63d") } >db.decrementingOperationDemo.insertOne({"ProductName":"Product-3", "ProductPrice":994}); { "acknowledged" : true, "insertedId" : ObjectId("5cd7a8c66d78f205348bc63e") } >db.decrementingOperationDemo.insertOne({"ProductName":"Product-4", "ProductPrice":1000}); { "acknowledged" : true, "insertedId" : ObjectId("5cd7a8d06d78f205348bc63f") }Following is the query to display all documents from a collection with the help of find() method −> db.decrementingOperationDemo.find().pretty();This will produce the following output −{ "_id" : ObjectId("5cd7a8ae6d78f205348bc63c"), "ProductName" : "Product-1", "ProductPrice" : 756 } { "_id" : ObjectId("5cd7a8b86d78f205348bc63d"), "ProductName" ... Read More
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
499 Views
For this, you can use COLLATE. Following is the syntax −select *from yourTableName where yourColumnName LIKE yourValue COLLATE utf8_bin;Let us first create a table −mysql> create table DemoTable ( LastName varchar(100) ); Query OK, 0 rows affected (0.51 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Brown'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values('BROWN'); Query OK, 1 row affected (0.29 sec) mysql> insert into DemoTable values('brown'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('BRoWN'); Query OK, 1 row affected (0.14 sec)Display all records ... Read More
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
497 Views
Let us first create a table −mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, Score int ); Query OK, 0 rows affected (0.89 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(Score) values(67); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable(Score) values(78); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable(Score) values(90); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable(Score) values(56); Query OK, 1 row affected (0.13 sec)Display all records from the table using select statement −mysql> select *from DemoTable;Output+----+-------+ ... Read More