Joining data in muliple tables

Hi, i was wondering if any of you guys could help me…

I need to join some data from the following tables… Basically if i do a select on the second table i can bring up the name of a download and it’s category id… the thing is, the category id has a name related to it but that’s in another table… How do i bring the dl_title in the second table and the cat_name in the first table together using the cat_id??

I had to trim the tables down because the forum thought i was trying to spam it?

Thanks
Andrew

Below are my tables…

Category name, id and descriptions (this table is called dl_cats)

cat_id
cat_name
cat_descr

Download name, id and descriptions (this table is called (dl_downloads_

dl_id
dl_cat
dl_title
dl_author
dl_description
dl_url
dl_hits

So far i have this…

select dl_title FROM dl_downloads JOIN dl_cats on dl_downloads.dl_cat = dl_cats.cat_id;

All this is saying doing though is saying that the dl_cat on the dl_downloads table = the cat_id on the dl_cats table, i need to actually pull up the category name based on the id number :-(

To get all data based on the cat_id use:

SELECT
c.cat_id,
c.cat_name,
c.cat_descr,
d.dl_id
d.dl_cat
d.dl_title
d.dl_author
d.dl_description
d.dl_url
d.dl_hits
FROM
dl_cats AS c
LEFT JOIN
dl_downloads AS d ON (d.dl_cat = c.cat_id)
WHERE
c.cat_id = x
;

To get the cat_id by dl_id use:
SELECT
c.cat_name
FROM
dl_cats AS c
LEFT JOIN
dl_downloads AS d ON (d.dl_cat = c.cat_id)
WHERE
d.dl_id = n
;

With this you should be able to get you’re goal!

Sponsor our Newsletter | Privacy Policy | Terms of Service