Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
06-17-2011, 02:29 PM #1
Query 2 tables, limit results of 1 table. How?
First time I've ever done anything like querying 2 tables at a time, and I'm struggling. I have the following query
SELECT categories.id, categories.listing, categories.catname, subcategories.catid, subcategories.subcat, subcategories.listings, subcategories.url FROM categories LEFT JOIN subcategories ON categories.id=subcategories.catid ORDER BY categories.catname,subcategories.subcat ASC
Last edited by Nightfire; 06-17-2011 at 08:33 PM.
06-17-2011, 05:26 PM #2
- Join Date
- Mar 2006
- St. Catharines, Ontario Canada
- Thanked 149 Times in 140 Posts
Two separate queries using a UNION ALL to join the queries.
Users who have thanked guelphdad for this post:
06-17-2011, 08:31 PM #3
06-18-2011, 03:25 AM #4
- Join Date
- Apr 2003
- in my house
- Thanked 201 Times in 197 Posts
you may prefer to write the query in that sort of format but you can save typing time by using an 'alias'
and I find this helps with 'seeing' where commas have run away and hidden somewhere.Code:SELECT c.id, c.listing, c.catname, s.catid, s.subcat, s.listings, s.url FROM categories AS c LEFT JOIN subcategories AS s ON c.id=s.catid ORDER BY c.catname,s.subcat ASC
Code:SELECT c.id , c.listing , c.catname , s.catid , s.subcat , s.listings , s.url FROM categories AS c LEFT JOIN subcategories AS s ON c.id=s.catid ORDER BY c.catname,s.subcat ASC
Users who have thanked bazz for this post:
06-18-2011, 05:38 PM #5
Cheers for that, didn't know about the alias thing