Found 4381 Articles for MySQL

Why is it not good practice to use date values with two-digits years in MySQL?

Daniol Thomas
Updated on 20-Jun-2020 06:21:36

218 Views

As we know that, YEAR(2) stores a year in 2-digit format. For example, we can write 69 to store 1969 as a year. In YEAR (2), the year can be specified from 1970 to 2069 (70 to 69).MySQL interprets 2-digit year values with the help of following rules −Year values in the range 00-69 are converted to 2000-2069. Year values in the range 70-99 are converted to 1970-1999.We must not store date values as a 2-digit format because values stored in this format becomes vague as the century is unknown.It can be understood more clearly with the help of following MySQL ... Read More

While fetching the data as output, how can I use multiple conditions on same column?

Arushi
Updated on 20-Jun-2020 06:23:33

159 Views

Followings are the ways in which we can write a query that returns only records that matches multiple conditions on the same columnBy using ‘OR’ logical operatorAs we know that MySQL ‘OR’ operator compares two expressions and returns TRUE if either of the expression is TRUE. Following example demonstrate that how we can use ‘OR’ operator for multiple conditions on the same columnmysql> Select * from Student WHERE Name = 'Gaurav' OR Name = 'Aarav'; +------+--------+---------+-----------+ | Id   | Name   | Address | Subject   | +------+--------+---------+-----------+ | 1    | Gaurav | Delhi   | Computers ... Read More

How can we get the sorted MySQL output?

Swarali Sree
Updated on 20-Jun-2020 06:21:03

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

How can MySQL interpret the number and string, having no delimiter, as a date?

varma
Updated on 29-Jan-2020 06:48:06

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

What MySQL returns on using any other character than ‘T’ or ‘Space’ between date and time parts?

usharani
Updated on 29-Jan-2020 06:48:45

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)

How can I use any character, at the place of space, in MySQL TIMESTAMP to distinguish between date and time parts?

varun
Updated on 29-Jan-2020 06:49:22

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)

Which punctuation character can be used as the delimiter between MySQL time parts?

Krantik Chavan
Updated on 29-Jan-2020 06:50:19

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

Which punctuation character can be used as the delimiter between MySQL date parts?

Prabhas
Updated on 29-Jan-2020 06:51:13

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)

How can we fetch a particular row as output from a MySQL table?

Ayyan
Updated on 20-Jun-2020 06:20:28

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)

How can we fetch one or more columns as output from a MySQL table?

Ankith Reddy
Updated on 29-Jan-2020 06:33:57

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

Advertisements