ShootingBlanks Posted October 18, 2007 Share Posted October 18, 2007 Hello. I have the following query that works and brings up the first 15 records in my database table: SELECT documents.doc_id, documents.title_full, documents.updated, DATE_FORMAT(documents.updated, '%m-%d-%Y') AS updated FROM documents, doc_cat_lookup WHERE documents.live_doc = 'y' LIMIT 15 Now, I want to only show the ones that were updated the most recently, so I added an "ORDER BY" line after the "WHERE" line to make the query this: SELECT documents.doc_id, documents.title_full, documents.updated, DATE_FORMAT(documents.updated, '%m-%d-%Y') AS updated FROM documents, doc_cat_lookup WHERE documents.live_doc = 'y' ORDER BY updated DESC, title_full ASC LIMIT 15 However, now all that comes up is the one most recently updated record, repeated 15 times. Any ideas where I'm going wrong here??? Thanks!!! Quote Link to comment Share on other sites More sharing options...
Mirkules Posted October 18, 2007 Share Posted October 18, 2007 I think this happens because you didn't specify a relation between the two tables (WHERE documents.id = doc_cat_lookup.id, for example). If you have N records in documents, and M records in doc_cat_lookup, and you are getting MxN results. The reason you didn't see it before is because you had the LIMIT statement (try taking it out from the original query and you'll see what I mean). Quote Link to comment Share on other sites More sharing options...
ShootingBlanks Posted October 18, 2007 Author Share Posted October 18, 2007 Fixed it. Thanks!!! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.