我不得不称为books
和authors
。MySQL:如何根据可用性在另一个表中选择
这是我books
表:
它包含本书中,作者姓名和书中的描述的标题。
这是我authors
表:
它包含了作者的名字,所在的城市生活的作家和作者肖像(介绍)。
我的问题是:我如何SELECT *
从books
行作者城市建立为例如。 Berlin
在authors
表中。
在这种情况下,当city = Berlin时,应该选择title = "Something title AAA"
和title = "Something title DDD"
的行。
这是我已经试过:
$stmt = $pdo->prepare('SELECT title, author, description FROM books JOIN authors ON :city = city');
$stmt->execute(array(':city' => "Berlin"));
但它不工作。我没有输出。我究竟做错了什么?
对于初学者来说,'ON:城市'就是事情开始的地方*“去南部”*。你不能以这种方式绑定它,因为PDO不知道提前做什么。 http://php.net/manual/en/pdo.error-handling.php会引发你一些关于它的事情。 –
提示:JOIN条件在作者身上,不在城市。 –
那么,我该怎么办? – user7128548