SQL Query

Status
Not open for further replies.

ziycon

New Member
I have this query below:
Code:
$sql = "SELECT id,name,date FROM releases WHERE date>='".date("Y-m-d")."' ORDER BY date ASC LIMIT ".$limit."";
It displays anything thats equal or in the future of the current date. But say i have 10 results on screen and five are the date 24-08-2007 and five are the date 28-08-2007, they are grouped together which is fine.

Now what im trying to do which wont work for me is to take the five '24' dated ones and order from a-z and then the five '28' ones and order from a-z like below:

24-08-2007 a
24-08-2007 c
24-08-2007 h
24-08-2007 m
24-08-2007 q
28-08-2007 d
28-08-2007 i
28-08-2007 o
28-08-2007 r
28-08-2007 w

Can anyone see where im going wrong?
 

daviddoran

New Member
Well taking the a-z column as "LETTER" you would do this:

$sql = "SELECT id,name,date FROM releases WHERE date>='".date("Y-m-d")."' ORDER BY date ASC, LETTER ASC LIMIT ".$limit."";
 

ziycon

New Member
Well taking the a-z column as "LETTER" you would do this:

$sql = "SELECT id,name,date FROM releases WHERE date>='".date("Y-m-d")."' ORDER BY date ASC, LETTER ASC LIMIT ".$limit."";

Sorry, i was really clear there, they aren't just letters, there strings but i want them from a-z based on the first character of the string, if you get me?!?
 

daviddoran

New Member
Ok, don't know how I missed the name column in the query!

Well surely the query would be this then: (simply order by date, then order by name alphabetically)

$sql = "SELECT id,name,date FROM releases WHERE date>='".date("Y-m-d")."' ORDER BY date ASC, name ASC LIMIT ".$limit."";
 

ziycon

New Member
Thanks david, i was using the query below with the 'AND' statement which was messing up the results, thanks again.

Code:
 $sql = "SELECT id,name,date FROM releases WHERE date>='".date("Y-m-d")."' ORDER BY date ASC AND name ASC LIMIT ".$limit."";
 
Status
Not open for further replies.
Top