Joining three tables using MySQL

前端 未结 9 2468
隐瞒了意图╮
隐瞒了意图╮ 2020-11-22 10:40

I have three tables named

**Student Table**
-------------
id    name
-------------
1     ali
2     ahmed
3     john
4     king

**Course Table**
------------         


        
9条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-22 11:06

    Just adding a point to previous answers that in MySQL we can either use

    table_factor syntax 
    

    OR

    joined_table syntax
    

    mysql documentation

    Table_factor example

    SELECT prd.name, b.name 
    FROM products prd, buyers b
    

    Joined Table example

    SELECT prd.name, b.name 
    FROM products prd
     left join buyers b on b.bid = prd.bid;
    

    FYI: Please ignore the fact the the left join on the joined table example doesnot make much sense (in reality we would use some sort of join table to link buyer to the product table instead of saving buyerID in product table).

提交回复
热议问题