How do you join on the same table, twice, in mysql?

后端 未结 3 1491
面向向阳花
面向向阳花 2020-11-22 10:46

I have 2 tables. One (domains) has domain ids, and domain names (dom_id, dom_url).

the other contains actual data, 2 of which columns require a TO and FROM domain na

3条回答
  •  春和景丽
    2020-11-22 11:09

    Given the following tables..

    Domain Table
    dom_id | dom_url
    
    Review Table
    rev_id | rev_dom_from | rev_dom_for
    

    Try this sql... (It's pretty much the same thing that Stephen Wrighton wrote above) The trick is that you are basically selecting from the domain table twice in the same query and joining the results.

    Select d1.dom_url, d2.dom_id from
    review r, domain d1, domain d2
    where d1.dom_id = r.rev_dom_from
    and d2.dom_id = r.rev_dom_for
    

    If you are still stuck, please be more specific with exactly it is that you don't understand.

提交回复
热议问题