- 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 6703 Articles for Database
![Kumar Varma](https://www.tutorialspoint.com/assets/profiles/13883/profile/60_73481-1512711460.jpg)
97 Views
The stripos() equivalent in MySQL is INSTR(), which returns the position of the first occurrence of a string in another string. Following is the syntax −select instr(yourColumnName, yourWord) As anyAliasName from yourTableName;Let us first create a table −mysql> create table DemoTable -> ( -> Title text -> ); Query OK, 0 rows affected (1.22 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('MySQL is my favourite subject'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('MongoDB is not my favourite subject'); Query OK, 1 row affected (0.20 sec)Display ... Read More
![Rama Giri](https://www.tutorialspoint.com/assets/profiles/13881/profile/60_68188-1512710896.jpg)
659 Views
To remove seconds from MySQL datetime, use UPDATE and SET as in the following syntax −update yourTableName set yourDateColumnName=yourDateColumnName -second(yourDateColumnName);Let us first create a table −mysql> create table DemoTable -> ( -> Shippingdatetime datetime -> ); Query OK, 0 rows affected (0.76 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('2019-01-21 12:05:20'); Query OK, 1 row affected (0.25 sec) mysql> insert into DemoTable values('2019-03-01 10:23:35'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values('2019-06-09 11:00:56'); Query OK, 1 row affected (0.14 sec)Display all records from the table ... Read More
![Kumar Varma](https://www.tutorialspoint.com/assets/profiles/13883/profile/60_73481-1512711460.jpg)
179 Views
Let us first create a table −mysql> create table DemoTable -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> Subject varchar(100) -> ); Query OK, 0 rows affected (0.76 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(Subject) values('C'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable(Subject) values('MongoDB'); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable(Subject) values('Java'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable(Subject) values('MongoDB'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable(Subject) ... Read More
![Rama Giri](https://www.tutorialspoint.com/assets/profiles/13881/profile/60_68188-1512710896.jpg)
74 Views
To find the greatest value among four tables, you can use the method GREATEST(). Following is the query to create first table −mysql> create table DemoTable1 -> ( -> Value int -> ); Query OK, 0 rows affected (0.70 sec)Insert some records in the first table using insert command −mysql> insert into DemoTable1 values(10); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable1 values(60); Query OK, 1 row affected (0.14 sec)Display all records from the first table using select statement −mysql> select *from DemoTable1;Output+-------+ | Value | +-------+ | 10 | ... Read More
![Kumar Varma](https://www.tutorialspoint.com/assets/profiles/13883/profile/60_73481-1512711460.jpg)
1K+ Views
For this, you can use SHOW COLUMNS command. Following is the syntax. Here, we have set the string using LIKE −SHOW COLUMNS FROM yourTableName LIKE ‘yourStringValue’;Let us first create a table −mysql> create table DemoTable -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> FirstName varchar(20), -> LastName varchar(20) -> ); Query OK, 0 rows affected (0.69 sec)Here is the query to select column names containing a specific string −mysql> SHOW COLUMNS FROM DemoTable LIKE 'FirstName';Output+-----------+-------------+------+-----+----------+-------+ | Field | Type | Null | ... Read More
![Rama Giri](https://www.tutorialspoint.com/assets/profiles/13881/profile/60_68188-1512710896.jpg)
406 Views
For this, you can use the DEFAULT CURRENT_TIMESTAMP clause in MySQL. Following is the syntax −CREATE TABLE yourTableName ( yourColumnName1 dataType1, yourColumnName timestamp DEFAULT CURRENT_TIMESTAMP );Let us first create a table −mysql> create table DemoTable -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> DueDate timestamp default current_timestamp -> ); Query OK, 0 rows affected (0.86 sec)Now you can insert some records in the table using insert command −mysql> insert into DemoTable values(); Query OK, 1 row affected (0.16 sec)Display all records from the table using select statement −mysql> select *from DemoTable;Output+----+---------------------+ ... Read More
![Nishtha Thakur](https://www.tutorialspoint.com/assets/profiles/13598/profile/60_104893-1512719058.jpg)
907 Views
To count number of elements in an array, use the aggregate framework. Let us first create a collection with documents −>db.countNumberOfElementsDemo.insertOne({"UserMessage":["Hi", "Hello", "Bye", "Awesome"]}); { "acknowledged" : true, "insertedId" : ObjectId("5cef8ec2ef71edecf6a1f6a1") }Display all documents from a collection with the help of find() method −> db.countNumberOfElementsDemo.find().pretty();This will produce the following output −{ "_id" : ObjectId("5cef8ec2ef71edecf6a1f6a1"), "UserMessage" : [ "Hi", "Hello", "Bye", "Awesome" ] }Following is the query to count number of elements in an array −> db.countNumberOfElementsDemo.aggregate({$project: { NumberOfElements: { $size:"$UserMessage" }}})This will produce ... Read More
![Smita Kapse](https://www.tutorialspoint.com/assets/profiles/13597/profile/60_103706-1512718957.jpg)
123 Views
Let us first create a collection with documents −> db.queryMongoValueDemo.insertOne( { _id:101, "ScoreDetails":[{Score:80}, {Score:45}, {Score:25}, {Score:70}] } ); { "acknowledged" : true, "insertedId" : 101 } > db.queryMongoValueDemo.insertOne( { _id:102, "ScoreDetails":[{Score:80}, {Score:24}, {Score:34}] } ); { "acknowledged" : true, "insertedId" : 102 } > db.queryMongoValueDemo.insertOne( { _id:103, "ScoreDetails":[{Score:99}, {Score:95}] } ); { "acknowledged" : true, "insertedId" : 103 }Display all documents from a collection with the help of find() method −> db.queryMongoValueDemo.find().pretty();This will produce the ... Read More
![Anvi Jain](https://www.tutorialspoint.com/assets/profiles/13591/profile/60_98631-1512716973.jpg)
143 Views
To get distinct first word from a string, you can use distinct(). Let us first create a collection with documents −> db.distinctFirstWordDemo.insertOne( { "_id": 100, "StudentName":"John", "StudentFeature": "John is a good player", "Subject":"MongoDB" } ); { "acknowledged" : true, "insertedId" : 100 } > db.distinctFirstWordDemo.insertOne( { "_id": 101, "StudentName":"Carol", "StudentFeature": "Carol is not a good player", "Subject":"MongoDB" } ); { "acknowledged" : true, "insertedId" : 101 }Display all documents from a collection ... Read More
![Nishtha Thakur](https://www.tutorialspoint.com/assets/profiles/13598/profile/60_104893-1512719058.jpg)
237 Views
To query all items, use find(). Let us first create a collection with documents −> db.queryAllItemsDemo.insertOne({"StudentDetails":{"StudentName":"John", "StudentSubject":["MongoDB", "MySQL"], "StudentSubjectPrice":[4000, 6000]}, "OtherDetails":{"UserAge":29, "UserCountryName":"US"}}); { "acknowledged" : true, "insertedId" : ObjectId("5cef74ecef71edecf6a1f69f") }Display all documents from a collection with the help of find() method −> db.queryAllItemsDemo.find().pretty();This will produce the following output −{ "_id" : ObjectId("5cef74ecef71edecf6a1f69f"), "StudentDetails" : { "StudentName" : "John", "StudentSubject" : [ "MongoDB", "MySQL" ], "StudentSubjectPrice" : [ 4000, ... Read More