Hi List. I think I'm having a very off day and need some confirmations on how MySQL works with it's result sets.
I have a couple of relational tables , the first holding the person's name and address for instance, and the other tables holds comments and complaints respectively. Each table has it's own id field, as well as a "master_id" that equals the id of the "main" table. The app that I'm writing (in PHP), lists the users with a simple "select * from main" , and this returns all the users currently on the system ( I have names as varchar and unique). My problem is now with the following: When the user clicks on one of the names, I want to do a couple of things: a) The user details be displayed along with all the comments and complaints that correspond to that users id located in the other tables. pseudo SQL -> "select * from comments where (place_holder id in comments) = (id in main table)"; b) Being able to list the comments and complaints in reverse order ie, older ones first: pseudo SQL -> "select * from comments where (place_holder id) = (id in main table) order by id desc"; c) List ONLY the last (newest) comments/complaints THIS IS WHERE I have problems: If I do a "select MAX(id), comment from comments where (place_holder id) = (id in main table)" will MySQL automagically grab the comment from the row that has the maximum ID? If so, is there a shorter way of doing this query? For my example here, it's not a big deal, but with larger tables with more collumns, having to specify the collumns in the query ( when I want ALL to be returned) becomes a bit of a hassle.. I basically want to say: return ONLY the last comment added where the id matches the supplied id from main_table. So, I need to Translate this to SQL... Can I do this with SQL, or must I first establish the id with the "select MAX(id) from comments where id = provided_id", and then do a new query " select * from comments where id = MAX(id) " Thanks -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]