In MySQL queries, why use join instead of where?

前端 未结 6 748
孤独总比滥情好
孤独总比滥情好 2020-11-22 17:34

It seems like to combine two or more tables, we can either use join or where. What are the advantages of one over the other?

6条回答
  •  南方客
    南方客 (楼主)
    2020-11-22 18:09

    You can't use WHERE to combine two tables. What you can do though is to write:

    SELECT * FROM A, B
    WHERE ...
    

    The comma here is equivalent to writing:

    SELECT *
    FROM A
    CROSS JOIN B
    WHERE ...
    

    Would you write that? No - because it's not what you mean at all. You don't want a cross join, you want an INNER JOIN. But when you write comma, you're saying CROSS JOIN and that's confusing.

提交回复
热议问题