I am trying to return some information that needs to consist of the name from one table and all the categories that each name belongs to from another.
However, I am searching using the category name. In other words I need to list all records that are under a specific category and also list the other categories they belong to.
I would like to be able to achieve this using one lot of sql code but am having difficulties. Here is what I have so far
This gets all records based on the sub category name
and this gets all of the category names
As you can see the second sql code needs the id of each record that is returned with the first lot of code.
How can I join these two pieces of sql together so that it returns the required records each of which contains all of the categories that they belong to?
Web Development Manager
However, I am searching using the category name. In other words I need to list all records that are under a specific category and also list the other categories they belong to.
I would like to be able to achieve this using one lot of sql code but am having difficulties. Here is what I have so far
This gets all records based on the sub category name
Code:
SELECT programmes.programmes_name
FROM ((programmes INNER JOIN categories_lookup ON programmes.programmes_id = categories_lookup.programmes_id)
INNER JOIN sub_categories ON categories_lookup.sub_categories_id = sub_categories.sub_categories_id)
WHERE (sub_categories.sub_categories_name = sub category name )
and this gets all of the category names
Code:
SELECT sub_categories_name FROM (sub_categories INNER JOIN categories_lookup ON sub_categories.sub_categories_id = categories_lookup.sub_categories_id) WHERE categories_lookup.programmes_id = the id of each record from above
As you can see the second sql code needs the id of each record that is returned with the first lot of code.
How can I join these two pieces of sql together so that it returns the required records each of which contains all of the categories that they belong to?
Web Development Manager