Rick, Welcome to the list - we try not to byte, er, bite... I am trying to do a select that will display events by category, but will NOT display a category name if it is empty (has no events).
2 tables: categories and events events contains a field called category_id that corresponds to the id of a category in categories. =a 'clean' structure, and you understand how to join the two tables - and your basic query appears below. I am doing a 'while' loop for the events inside a 'while' loop for the categories. It displays the category, then all events for that category. =ouch! This is thinking in 'procedural logic', eg C, PHP, programming languages; not 'relational logic/algebra' suited to a SQL RDBMS - but we know what you mean... =you will need to expand the query (below) to display information from the events table - currently the last clause of your spec (above) is not implemented (below). I am trying to find a simple way to NOT display the category if there are no events in that category. =check out the manual's discussion of IS [NOT] NULL, alternatively read up about different types of 'joins'. However I wouldn't get into that complication until you deal with the central issue below (get the db to respond with a superset of your data, then work on refining that result down to the level of precision/exclusion you require!) This seems logical, but does not produce any output: "SELECT category from categories WHERE categories.id = events.category_id" =On the face of it, you should get some answers back, except that you need to name both of the tables involved in the FROM clause. =Are you using native MySQL at the command line, or a management tool? (or are you being more complicated, and calling MySQL from a programming language) Keep things simple - use native SQL first (no interfacing issues), then cut-and-paste into a more complicated 'vehicle', if that's what you want to do. =If a problem persists at this level, could you come back to us the two table definitions and maybe some sample data? I can envision ways of getting this result that are more complicated that they should be. Is there a fairly simple way ? BTW, I just joined this list and this is my first post. Let me know if I am being unclear. =where there's a will, there's a way! =dn --------------------------------------------------------------------- Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php