GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   SQL masters: (https://gfy.com/showthread.php?t=573959)

Zester 02-09-2006 04:56 AM

SQL masters:
 
What is wrong with this Sub Query:
Code:

SELECT date
FROM  `records`
WHERE  STATUS  =  'published'
AND date = ( select max(date) FROM `records` )
LIMIT = 25;

it's suppose to spit out the date of the latest 25 articles in 'published' status and nothing more.

everestcash 02-09-2006 06:04 AM

i was thinking, is there a way to rewrite that query using 'order by id' or 'date' instead, without using a sub query. That'll be a simpler approach.

like

select from `records` where status = 'published' order by id desc limit 0, 25;

ddfGandalf 02-09-2006 06:09 AM

select date from records where status='published' order by date desc LIMIT 25;

woj 02-09-2006 06:13 AM

Quote:

Originally Posted by everestcash
select from `records` where status = 'published' order by id desc limit 0, 25;

:thumbsup

Pryda 02-09-2006 06:15 AM

Quote:

Originally Posted by Zester
What is wrong with this Sub Query:
Code:

SELECT date
FROM  `records`
WHERE  STATUS  =  'published'
AND date = ( select max(date) FROM `records` )
LIMIT = 25;

it's suppose to spit out the date of the latest 25 articles in 'published' status and nothing more.


Your query wants up to 25 record dates for articles published on the same date as the most recent record (published or not).

sickbeatz 02-09-2006 06:20 AM

SELECT date
FROM `records`
WHERE STATUS = 'published' ORDER BY date DESC LIMIT 25;


All times are GMT -7. The time now is 09:25 PM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2026, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123