Tuesday 10 February 2015

MySQL Database Interview Questions for Beginners and experienced (Page 5)

Below are some important MySQL interview questions which are asked in most MNC company interviews for beginners or professionals.

21. How To Use IN Conditions?
An IN condition is single value again a list of values. It returns TRUE, if the specified value is in the list.
Otherwise, it returns FALSE.
Some examples are given in the tutorial exercise below:
 SELECT 3 IN (1,2,3,4,5) FROM DUAL;
1
SELECT 3 NOT IN (1,2,3,4,5) FROM DUAL;
0
SELECT Y’ IN (‘F’,’Y’,I) FROM DUAL;
1

22. How To Use LIKE Conditions?
A LIKE condition is also called pattern patch. There are 3 main rules on using LIKE condition:
* is used in the pattern to match any one character.
* % is used in the pattern to match any zero or more characters.
* ESCAPE clause is used to provide the escape character in the pattern.
The following tutorial exercise provides you some good pattern matching examples:
SELECT GlobalGuideLine.com LIKE ‘%center% FROM DUAL;
1
SELECT GlobalGuideLine.com’ LIKE ‘%CENTER% FROM DUAL;
1
-- Case insensitive by default
SELECT GlobalGuideLine.com LIKE ‘%CENTER_com’ FROM DUAL;
1

23. How To Increment Dates by 1111 MvSQL?
If you have a date, and you want to increment it by 1 day, you can use the DATE_ADD(date, INTERVAL 1 DAY) function. You can also use the date interval add operation as “date + INTERVAL 1 DAY. The tutorial exercise below gives you some good examples:
SELECT DATE_ADD(DATE(1997-01-3 1), INTERVAL 1 DAY)
FROM DUAL;
1997-02-01
SELECT DATE(1997-01-31) + INTERVAL 1 DAY FROM DUAL;
1997-02-01

24. How To Calculate the Difference between Two Dates?
If you have two dates, and you want to know how many days between them, you can use the DATEDIFF(datel, date2) function as shown below:
SELECT DATEDI FF( DATE(’1997-02-28’), DATE(’1997-03-01’))
FROM DUAL;
-1 and different between two time is TIMEDIFF()

25. Flow To Present a Past Time in Hours, Minutes and Seconds?
If you want show an article was posted “n hours n minutes and n seconds ago’, you can use the TIMEDIFF(NOWO, pastTime) function as shown in the following tutorial exercise:
SELECT TIMEDIFF(NOWO, ‘2006-07-01 04:09:49’) FROM DUAL;
06:42:58
SELECT TIM E_FORMAT(TI M EDI FF( NOWO, ‘2006-06-30 04:09:49’),
‘%H hours, %i minutes and %s seconds ago.’) FROM DUAL;
30 hours, 45 minutes and 22 seconds ago.
More Questions & Answers :-

No comments:

Post a Comment