Share it

Bookmark and Share

Translate

Friday, April 20, 2012

0 Interview questions

How to find the date diffrence greater than a particular number using mysql?
 eg: date difference is greater than 10
Ans:DATEDIFF( );
       eg:SELECT DATE_FORMAT(FROM_DAYS(DATEDIFF(NOW(), dob)),
"%Y")+0 AS age from     sometable

Q.Find the records match in table,and also stop when first match occurs?
Ans:SELECT * FROM (
    SELECT * FROM table WHERE name1 like "Bob" limit 1
    UNION SELECT * FROM table WHERE name2 like "Bob" limit 1
    UNION SELECT * from table WHERE nicknames rlike 
"[,]Bob[,]|[,]Bob$" limit 1) AS t1 LIMIT 1;
The limit 1 on each one keeps the database from pulling up 50,000 Bob records just to
show you one of them.
Q .how to optimize sql querys?
Ans:
    * Use primary keys
    * Avoid select *
    * Be as specific as you can when building your conditional statements
    * De-normalisation can often be more efficient
    * Table variables and temporary tables (where available) will often be
 better than using a large source    table
    * Partitioned views
    * use indices and constraints

Q.Difference b/w having and where?
    If a condition refers to an aggregate function, put that condition in the HAVING clause.
 Otherwise, use the   

WHERE clause.
Here's another rule: You can't use HAVING unless you also use GROUP BY.
SELECT state,SUM(baldue)
FROM Test
GROUP by state
HAVING SUM(baldue) > 0
ORDER BY state


0 comments:

Post a Comment

Thanks for your valuable Comment

 

TechnoTipworld- Tips,Tricks,Technology Copyright © 2011 - |- Template created by O Pregador - |- Powered by Blogger Templates