如何根据条件联接2个表?

时间:2020-06-18 07:10:27

标签: mysql

我想加入两个表:book_details的那些书中的imdb_indeximdb_index is >=600;

enter image description here

这是我尝试过的:

select *from imdb_index where imdb_index>=600 as x join book_details as y on x.isbn=y.isbn;

3 个答案:

答案 0 :(得分:1)

SELECT * FROM imdb_index AS x JOIN book_details AS y ON x.isbn = y.isbn 
WHERE x.imdb_index>=600;

有关加入访问的更多详细信息 https://www.mysqltutorial.org/mysql-join/

答案 1 :(得分:0)

where和join子句放在错误的位置

    select * 
    from imdb_index x 
    join book_details y on x.isbn=y.isbn
    where y.imdb_index>=600  ;

join子句必须在where子句

之前

答案 2 :(得分:0)

通过使用以下查询,您将能够从imdb_index为> = 600的表中获取数据。

   select * 
   from imdb_index as im 
   join book_details as bd
   on im.isbn = bd.isbn 
   where im.imdb_index>=600;

您在where之前使用join条件。您应该先执行Join,然后才应该使用where

强烈建议您阅读并观看有关joins的一些教程。

以下链接将为您提供帮助。

1。https://www.w3schools.com/sql/sql_join.asp

2。https://dev.mysql.com/doc/refman/8.0/en/join.html

相关问题