-1

I have

tbl_ticket_categories(id , category_name , description , site_referers_id)

tbl_ticket_repliers(id , user_id , category_id , site_referers_id)

tbl_users(id , role_id , username , password )

I want to select all category_name and description from tbl_ticket_categories where site_referers_id = 1

and also those username whose user_id is in tbl_ticket_repliers.

4

2 に答える 2

1
select category_name,description,username from tbl_ticket_categories as ttc
join tbl_ticket_repliers as ttr on ttr.category_id=ttc.id
join tbl_users as tu on tu.id=ttc.user_id
where site_referers_id = 1

これは、正確な結果が得られるクエリです。一度確認してください

于 2012-07-28T10:34:58.927 に答える
0
SELECT category_name, description, tu.username 
   FROM tbl_ticket_categories tc 
     INNER JOIN tbl_ticket_repliers tr 
        ON tc.id = tr.category_id
     INNER JOIN tbl_users tu 
        ON tr.user_id = tu.id
   WHERE tc.site_referers_id = 1

See this fiddle

于 2012-07-28T10:32:15.793 に答える