Found 6702 Articles for Database

Is name a reserved word in MySQL?

George John
Updated on 30-Jul-2019 22:30:26

247 Views

No, name is not a reserved word in MySQL, you can use without backtick symbol. If you are working on a reserved word then use backtick symbol. Let us first create a table −mysql> create table name    (    name varchar(10)    ); Query OK, 0 rows affected (0.78 sec)Now you can insert some records in the table using insert command −mysql> insert into name values('John'); Query OK, 1 row affected (0.13 sec) mysql> insert into name values('Carol'); Query OK, 1 row affected (0.14 sec)Display all records from the table using select statement −mysql> select *from name;Output+-------+ | name ... Read More

How to sort by value with MySQL ORDER BY?

Chandu yadav
Updated on 30-Jul-2019 22:30:26

150 Views

For this, use the ORDER BY clause. Let us first create a table −mysql> create table DemoTable    (    StudentId int    ); Query OK, 0 rows affected (0.59 sec)Now you can insert some records in the table using insert command −mysql> insert into DemoTable values(100); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values(60); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values(70); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values(45); Query OK, 1 row affected (0.24 sec) mysql> insert into DemoTable values(55); Query OK, 1 row affected ... Read More

Getting a list of values by using MongoDB $group?

Nishtha Thakur
Updated on 30-Jul-2019 22:30:26

1K+ Views

To get a list of values, use $group aggregation along with $push operator. Let us first create a collection with documents −> db.groupByDemo.insertOne({"UserName":"John", "Subject":"MongoDB"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd69f0457806ebf1256f136") } > db.groupByDemo.insertOne({"UserName":"Larry", "Subject":"MySQL"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd69f0657806ebf1256f137") } > db.groupByDemo.insertOne({"UserName":"John", "Subject":"Java"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd69f0d57806ebf1256f138") } > db.groupByDemo.insertOne({"UserName":"John", "Subject":"C"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd69f1357806ebf1256f139") } > db.groupByDemo.insertOne({"UserName":"Larry", "Subject":"SQL Server"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd69f1c57806ebf1256f13a") }Following is the query to display all documents from a collection with the help ... Read More

How to insert mm/dd/yyyy format dates in MySQL?

Arjun Thakur
Updated on 30-Jul-2019 22:30:26

5K+ Views

For this, use STR_TO_DATE(). Following is the syntax −insert into yourTableName values(STR_TO_DATE(yourDateValue, yourFormatSpecifier));Let us first create a table −mysql> create table DemoTable    (    ShippingDate date    ); Query OK, 0 rows affected (0.81 sec)Insert some records in the table using insert command : Here, we are inserting formatted dates using date formats like m, d, y, etc −mysql> insert into DemoTable values(STR_TO_DATE('06-01-2019', '%m-%d-%Y')); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable values(STR_TO_DATE('01-31-2019', '%m-%d-%Y')); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable values(STR_TO_DATE('02-01-2018', '%m-%d-%Y')); Query OK, 1 row affected (0.27 sec)Display all records ... Read More

How to get day name from timestamp in MySQL?

Ankith Reddy
Updated on 30-Jul-2019 22:30:26

233 Views

To get the day name from timestamp, use dayname() function −select dayname(yourColumnName) from yourTableName;    Let us first create a table :    mysql> create table DemoTable    (    LoginDate timestamp    ); Query OK, 0 rows affected (0.52 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('2019-06-01'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('2019-06-02'); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable values('2019-06-03'); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable values('2019-06-04'); Query OK, 1 row affected (0.11 sec) mysql> insert into ... Read More

How to get the date between TODAY and TODAY-7”?

George John
Updated on 30-Jul-2019 22:30:26

6K+ Views

To get the date between dates, you need to use. Here, we are getting the dates between today and today-7 days −select *from yourTableName where DATE(yourColumnName) > (NOW() - INTERVAL 7 DAY);Note : Let’s say the current date is '2019-06-02’ Let us first create a table.mysql> create table DemoTable    (    LoginDate date    ); Query OK, 0 rows affected (0.57 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('2018-03-21'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values('2019-05-22'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values('2019-05-27'); ... Read More

How to find documents with exactly the same array entries as in a MongoDB query?

Smita Kapse
Updated on 30-Jul-2019 22:30:26

76 Views

For this, use the $all operator. Let us first create a collection with documents −>db.findDocumentExactlySameInArrayDemo.insertOne({"TechnicalSubjects":["C++", "Java", "MongoDB"]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd69a5f57806ebf1256f12e") } >db.findDocumentExactlySameInArrayDemo.insertOne({"TechnicalSubjects":["MySQL", "Java", "MongoDB"]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd69ac057806ebf1256f12f") } >db.findDocumentExactlySameInArrayDemo.insertOne({"TechnicalSubjects":["C#", "Python", "MongoDB"]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd69ad457806ebf1256f130") } >db.findDocumentExactlySameInArrayDemo.insertOne({"TechnicalSubjects":["MySQL", "C", "MongoDB"]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd69adf57806ebf1256f131") }Following is the query to display all documents from a collection with the help of find() method −> db.findDocumentExactlySameInArrayDemo.find().pretty();This will produce the following output −{    "_id" : ObjectId("5cd69a5f57806ebf1256f12e"),    "TechnicalSubjects" : [     ... Read More

How to get number of rows in a table without using count(*) MySQL query?

Chandu yadav
Updated on 30-Jul-2019 22:30:26

596 Views

You can use count(1). Let us first see the syntax −select count(1) from yourTableName;Let us first create a table −mysql> create table DemoTable    (    StudentName varchar(100)    ); Query OK, 0 rows affected (0.84 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(StudentName) values('John Smith'); Query OK, 1 row affected (0.24 sec) mysql> insert into DemoTable(StudentName) values('Chris Brown'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable(StudentName) values('David Miller'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable(StudentName) values('Carol Taylor'); Query OK, 1 row affected (0.15 sec)Display all records from ... Read More

Get maximum and minimum value in MongoDB?

Anvi Jain
Updated on 30-Jul-2019 22:30:26

1K+ Views

Use $max and $min operator along with aggregate framework to get the maximum and minimum value. Let us first create a collection with documents −> db.maxAndMinDemo.insertOne({"Value":98}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd698a357806ebf1256f129") } > db.maxAndMinDemo.insertOne({"Value":97}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd698af57806ebf1256f12a") } > db.maxAndMinDemo.insertOne({"Value":69}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd698b357806ebf1256f12b") } > db.maxAndMinDemo.insertOne({"Value":96}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd698b657806ebf1256f12c") } > db.maxAndMinDemo.insertOne({"Value":99}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd698b957806ebf1256f12d") }Following is the query to display all documents from a collection with the help of find() method ... Read More

How to find string count of a particular id in a column using a MySQL query?

Arjun Thakur
Updated on 30-Jul-2019 22:30:26

115 Views

For this, use the CHAR_LENGTH() function in MySQL. Let us first create a table −mysql> create table DemoTable    (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    Subject longtext    ); Query OK, 0 rows affected (1.17 sec)Now you can insert some records in the table using insert command −mysql> insert into DemoTable(Subject) values('MySQL, MongoDB'); Query OK,  1 row affected (0.20 sec) mysql> insert into DemoTable(Subject) values('MySQL, MongoDB'); Query OK,  1 row affected (0.17 sec) mysql> insert into DemoTable(Subject) values('MongoDB'); Query OK,  1 row affected (0.13 sec) mysql> insert into DemoTable(Subject) values('MySQL'); Query OK,  1 row affected (0.15 sec) Display all records from the table using select statement : mysql> select *from DemoTable;Output+----+---------------+ | Id | Subject | +----+---------------+ | 1 | MySQL, MongoDB | | 2 | MySQL, MongoDB | | ... Read More

Advertisements