- 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
82 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)
58 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
51 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)
2K+ 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)
196 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
285 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)
421 Views
We can add ‘half year interval’ in date ith the following ways −(A) By adding interval of 6 Monthsmysql> Select '2017-06-20' + INTERVAL 6 Month AS 'After Half Year Interval'; +--------------------------+ | After Half Year Interval | +--------------------------+ | 2017-12-20 | +--------------------------+ 1 row in set (0.00 sec)(B) By adding interval of 2 quartersmysql> Select '2017-06-20' + INTERVAL 2 Quarter AS 'After Half Year Interval'; +--------------------------+ | After Half Year Interval | +--------------------------+ | 2017-12-20 | +--------------------------+ 1 row in set (0.00 sec)Above query will add half year interval in date with the help of Quarter keyword.
194 Views
We can fetch all the record from a MySQL table by using SELECT * from table_name; query. An example is as follows, fetched all the records from ‘Employee’ table −mysql> Select * from Employee; +------+--------+ | Id | Name | +------+--------+ | 100 | Ram | | 200 | Gaurav | | 300 | Mohan | +------+--------+ 3 rows in set (0.00 sec)
50 Views
We can create a function, which accepts the date values as its argument and returns the difference in year, month and days, as followsmysql> CREATE FUNCTION date_difference(Date1 DATE, date2 DATE) RETURNS VARCHAR(30) -> RETURN CONCAT( -> @years := TIMESTAMPDIFF(YEAR, date1, date2), IF (@years = 1, ' year, ', ' years, '), -> @months := TIMESTAMPDIFF(MONTH, DATE_ADD(date1, INTERVAL @years YEAR), date2), IF (@months = 1, ' month, ', ' months, '), -> @days := TIMESTAMPDIFF(DAY, DATE_ADD(date1, INTERVAL @years * 12 + @months MONTH), date2), IF (@days = 1, ' day', ' days')) ; Query OK, 0 ... Read More