Wednesday, 11 May 2016

Most Common Useful MySql Queries.

At the time of MySql Query implementation, most of the time we are confusing rarely used queries. Below are the solutions for in real time scenario  MySql queries.

Get the parent Title:

SELECT *,(select vTitle from classifieds_categories c2 where c1.iParentId = c2.iId) as title FROM `classifieds_categories` c1

Get 2nd Height price:

SELECT max(vPrice) FROM `classifieds_list` where vPrice!= (SELECT max(vPrice) FROM `classifieds_list`);

Group wise latest records:


SELECT r1.* FROM `records` r1 Left join `records` r2 ON (r1.vGroup = r2.vGroup AND r2.iId > r1.iId) WHERE r2.iId IS NULL

Group wise first records:

SELECT r1.* FROM `records` r1 Left join `records` r2 ON (r1.vGroup = r2.vGroup AND r2.iId > r1.iId) WHERE r2.iId IS NULL

No comments:

Post a Comment