Use Arithmetic Operators with INTERVAL Keyword in MySQL

Nancy Den
Updated on 20-Jun-2020 06:24:28

245 Views

We can use arithmetic operators (+, -, *, /) with the unit values of INTERVAL keyword as follows −Use of Addition (+)mysql> Select date('2017-10-22' + INTERVAL 2+2 Year) AS 'Date After (2+2)Years'; +------------------------+ | Date After (2+2) Years | +------------------------+ | 2021-10-22             | +------------------------+ 1 row in set (0.00 sec)Use of Subtraction (-)mysql> Select date('2017-10-22' + INTERVAL 2-2 Year) AS 'Date After (2-2)Years'; +------------------------+ | Date After (2-2) Years | +------------------------+ | 2017-10-22             | +------------------------+ 1 row in set (0.00 sec)Use of Multiplication (*)mysql> Select date('2017-10-22' + INTERVAL ... Read More

Use Multiple Conditions on the Same Column in SQL

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

185 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

Avoid Using Two-Digit Years in MySQL

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

248 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

Get Sorted MySQL Output

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

149 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

Light Speed Out Animation Effect with CSS

Nishtha Thakur
Updated on 20-Jun-2020 06:20:40

198 Views

To create a light speed out effect with CSS, you can try to run the following code:Live Demo                    .animated {             background-image: url(/css/images/logo.png);             background-repeat: no-repeat;             background-position: left top;             padding-top:95px;             margin-bottom:60px;             -webkit-animation-duration: 1s;             animation-duration: 1s;             -webkit-animation-fill-mode: both;             animation-fill-mode: both;          }          @-webkit-keyframes lightSpeedOut {             0% {                -webkit-transform: translateX(0%) skewX(0deg);                opacity: 1;             }             100% {             -webkit-transform: translateX(100%) skewX(-30deg);             opacity: 0;             }          }          @keyframes lightSpeedOut {             0% {                transform: translateX(0%) skewX(0deg);                opacity: 1;             }             100% {                transform: translateX(100%) skewX(-30deg);                opacity: 0;             }          }          .lightSpeedOut {             -webkit-animation-name: lightSpeedOut;             animation-name: lightSpeedOut;             -webkit-animation-timing-function: ease-in;             animation-timing-function: ease-in;          }          .animated.lightSpeedOut {             -webkit-animation-duration: 0.25s;             animation-duration: 0.25s;          }                           Reload page                function myFunction() {             location.reload();          }          

Fetch a Particular Row 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)

Meaning of SELECT Statement in MySQL and Its Usage

George John
Updated on 20-Jun-2020 06:19:49

208 Views

The SELECT command is used to fetch data from the MySQL database. You can use this command at mysql> prompt as well as in any script like PHP.SyntaxHere is generic syntax of SELECT command to fetch data from the MySQL table −SELECT field1, field2, ...fieldN FROM table_name1, table_name2... [WHERE Clause] [OFFSET M ][LIMIT N]Some important points about SELECT statement are as follows −We can use one or more tables separated by a comma to include various conditions using a WHERE clause, but the WHERE clause is an optional part of the SELECT command.We can fetch one or more fields in ... Read More

Use WHERE Clause with MySQL INSERT INTO Command

Fendadis John
Updated on 20-Jun-2020 06:17:22

7K+ Views

We can use conditional insert i.e. WHERE clause with INSERT INTO command in the case of new row insertion. It can be done with following ways −With the help of dummy tableIn this case, we insert the value from dummy table along with some conditions. The syntax can be as follows −INSERT INTO table_name(column1, column2, column3, …) Select value1, value2, value3, … From dual WHERE [conditional predicate];Examplemysql> Create table testing(id int, item_name varchar(10)); Query OK, 0 rows affected (0.15 sec) mysql> Insert into testing (id, item_name)Select 1, 'Book' From Dual Where 1=1; Query OK, 1 row affected (0.11 sec) ... Read More

Insert Values into a Table with MySQL Self-Computed Output

Jai Janardhan
Updated on 20-Jun-2020 06:15:32

163 Views

We can insert the values into a table with the help of the self-computed output returned by MySQL. In this case, we do not need to use dummy ‘dual’ table. The syntax can be as follows −INSERT INTO table_name(column1, column2, column3, …) Select value1, value2, value3, …;ExampleIn the example below, we have inserted the values in ‘testing’ table by using the MySQL self-computed output.mysql> Create table testing(id int, item_name varchar(10)); Query OK, 0 rows affected (0.15 sec) mysql> Insert into testing (id, item_name)Select 1, 'Book'; Query OK, 1 row affected (0.11 sec) Records: 1 Duplicates: 0 Warnings: 0 ... Read More

Compound Units in MySQL EXTRACT Function

Giri Raju
Updated on 20-Jun-2020 06:14:32

153 Views

MySQL EXTRACT() function can use following compound units −SECOND_MICROSECONDMINUTE_MICROSECONDHOUR_MICROSECONDDAY_MICROSECONDMINUTE_SECONDHOUR_SECONDHOUR_MINUTEDAY_SECONDDAY_MINUTEDAY_HOURYEAR_MONTHSome of the examples of these compound units used in EXTRACT() function are as follows −mysql> Select EXTRACT(YEAR_MONTH from '2017-10-20'); +---------------------------------------+ | EXTRACT(YEAR_MONTH from '2017-10-20') | +---------------------------------------+ |                             201710    | +---------------------------------------+ 1 row in set (0.00 sec)Above query will return the year and month value from the date.mysql> Select EXTRACT(DAY_HOUR from '2017-10-20 05:46:45'); +----------------------------------------------+ | EXTRACT(DAY_HOUR from '2017-10-20 05:46:45') | +----------------------------------------------+ |                               ... Read More

Advertisements