
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 6705 Articles for Database

124 Views
We know that MySQL SELECT command is used to fetch data from a MySQL table. When you select rows, the MySQL server is free to return them in any order, unless you instruct it otherwise by saying how to sort the result. But, we can sort a result set by adding an ORDER BY clause that names the column or columns which you want to sort.SyntaxSelect column1, column2, …, columN From table_name ORDER BY column1[column2, …];ExampleIn the example below, MySQL returns the result set sorted on the basis of column ‘Name’;mysql> Select Id, Name, Address from Student ORDER BY Subject; ... Read More

249 Views
If a string or number, even without any delimiter, in the format of YYYYMMDDHHMMSS or YYMMDDHHMMSS is making sense as the date is provided then MySQL interpret that string as a valid date.Examples are given for valid as well as invalid dates −mysql> Select Timestamp(20171022040536); +---------------------------+ | Timestamp(20171022040536) | +---------------------------+ | 2017-10-22 04:05:36 | +---------------------------+ 1 row in set (0.00 sec) mysql> Select Timestamp('20171022040536'); +-----------------------------+ | Timestamp('20171022040536') | +-----------------------------+ | 2017-10-22 04:05:36 | +-----------------------------+ 1 row in set (0.00 sec) mysql> Select Timestamp('171022040536'); +---------------------------+ | Timestamp('171022040536') | +---------------------------+ | 2017-10-22 04:05:36 ... Read More

80 Views
In that case, MySQL will return all zeros at the place of time along with correct date part. An example is as follows in which we used character ‘W’ at the place of ‘T’ or ‘Space’ between date and time part −mysql> Select TIMESTAMP('2017-10-20W06:10:36'); +----------------------------------+ | TIMESTAMP('2017-10-20W06:10:36') | +----------------------------------+ | 2017-10-20 00:00:00 | +----------------------------------+ 1 row in set, 1 warning (0.00 sec)

131 Views
We can use the only character ‘T’ (in Capital form only) at the place of space between date and time part. It can be elucidated with the help of the following example −mysql> Select TIMESTAMP('2017-10-20T06:10:36'); +----------------------------------+ | TIMESTAMP('2017-10-20T06:10:36') | +----------------------------------+ | 2017-10-20 06:10:36 | +----------------------------------+ 1 row in set (0.00 sec)

96 Views
As in the case of date values, MySQL also permits us to use a relaxed format for time. We can use any punctuation character between time parts as a delimiter. Some examples are as follows −mysql> Select timestamp('2017-10-20 04+05+36'); +----------------------------------+ | timestamp('2017-10-20 04+05+36') | +----------------------------------+ | 2017-10-20 04:05:36 | +----------------------------------+ 1 row in set (0.00 sec) mysql> Select timestamp('2017-10-20 04*05*36'); +----------------------------------+ | timestamp('2017-10-20 04*05*36') | +----------------------------------+ | 2017-10-20 04:05:36 | +----------------------------------+ 1 row in set (0.00 sec) mysql> Select timestamp('2017-10&20 04@05+36'); +----------------------------------+ | timestamp('2017-10&20 ... Read More

104 Views
In this matter, MySQL permits us to use a relaxed format to date. We can use any punctuation character between date parts as a delimiter. Some examples are as follows −mysql> Select date ('2016/10/20'); +---------------------+ | date ('2016/10/20') | +---------------------+ | 2016-10-20 | +---------------------+ 1 row in set (0.00 sec) mysql> Select date('2016^10^20'); +--------------------+ | date('2016^10^20') | +--------------------+ | 2016-10-20 | +--------------------+ 1 row in set (0.00 sec) mysql> Select date ('2016@10@20'); +---------------------+ | date ('2016@10@20') | +---------------------+ | 2016-10-20 | +---------------------+ 1 row in set (0.00 sec) mysql> Select date ('2016+10+20'); +---------------------+ | date ('2016+10+20') | +---------------------+ | 2016-10-20 | +---------------------+ 1 row in set (0.00 sec)

4K+ Views
For fetching a particular row as output, we need to use WHERE clause in the SELECT statement. It is because MySQL returns the row based on the condition parameter given by us after WHERE clause.ExampleSuppose we want to fetch a row which contains the name ‘Aarav’ from student table then it can be done with the help of the following query −mysql> Select * from Student WHERE Name = 'Aarav'; +------+-------+---------+---------+ | Id | Name | Address | Subject | +------+-------+---------+---------+ | 2 | Aarav | Mumbai | History | +------+-------+---------+---------+ 1 row in set (0.00 sec)

288 Views
The SELECT command can be used to fetch one or more columns as output from MySQL table. An example is given below to fetch one or more columnsmysql> Select * from Student; +------+---------+---------+-----------+ | Id | Name | Address | Subject | +------+---------+---------+-----------+ | 1 | Gaurav | Delhi | Computers | | 2 | Aarav | Mumbai | History | | 15 | Harshit | Delhi | Commerce | | 17 | Raman | Shimla | Computers | +------+---------+---------+-----------+ 4 rows in set (0.01 sec) ... Read More

390 Views
It is possible with the help of keyword Quarter as follows −mysql> Select '2017-06-20' + INTERVAL 1 Quarter AS 'After 3 Months Interval'; +-------------------------+ | After 3 Months Interval | +-------------------------+ | 2017-09-20 | +-------------------------+ 1 row in set (0.00 sec)