First of all, I apologize in advance if this is covered somewhere in a
FAQ. I did a Google search, but really couldn't find anything.
I'm having a problem with a simple select query. I've got users
uploading data into a database. I want to do something that seems as if
it should be really simple, but it isn't so far.
Basically, I want to retrieve the latest 12 records from the table,
sorted by the date-time field (uploaddate) then by a varchar field
(name). Here's the SQL that I'm using:
select * from tblcontent
where filetypeid=1 and release='Y'
order by uploaddate desc, name limit 12;
And here's the table schema:
Field,Type,Null ,Key,Default,Ex tra
ContentID,int(3 ),,PRI,NULL,aut o_increment
Name,varchar(50 ),,,,
Filename,varcha r(100),,,,
Thumbnail,varch ar(100),,,,
FileTypeID,int( 11),,,0,
UploadDate,date time,,,0000-00-00 00:00:00,
Description,tex t,,,,
ContributorID,i nt(10) unsigned,,,0,
Release,enum('Y ','N'),YES,,N,
The problem I'm running into is that while I am retrieving the most
recent 12 records, it's not sorting by the varchar field. Instead, the
'Name' field seems randomly sorted. If I change the sort order (name,
uploaddate desc), I don't get the records that I want.
This seems like it should be something very simple to do, but it's
driving me nuts and I really have no idea how to resolve the problem. I
know I'm probably doing something really stupid, but at this point I need
help.
I appreciate anyone's patience who's read through all of this, and any
answer will be most appreciated.
Comment