仅选择特定列的内部联接 3 个表

Inner join 3 tables with only specific columns selected

我无法解决这个问题,我有树表、内部联接并且我只选择了特定的列因为我担心如果我 就离开 SELECT[ 会出现性能问题=28=] * 完成工作

我有表:ugovori-artikliugovoriidsworking SELECT * query:

SELECT * FROM `ugovori-artikli`
INNER JOIN `ugovori`
ON `ugovori-artikli`.`ugovor_id` = `ugovori`.`id`
INNER JOIN `ids`
ON `ugovori`.`kupac_id` = `ids`.`id`
AND `ugovori-artikli`.`artikal` = ?

无效查询,我的尝试:

SELECT a.*,
b.*,
c.id, c.ime, c.prezime
FROM `ugovori-artikli` AS a
INNER JOIN `ugovori` AS b
ON `ugovori-artikli`.`ugovor_id` = `ugovori`.`id`
INNER JOIN `ids` AS c
ON `ugovori`.`kupac_id` = `ids`.`id`
AND `ugovori-artikli`.`artikal` = ?

我收到一个错误:

Error in query (1054): Unknown column 'ugovori-artikli.ugovor_id' in 'on clause'

使用别名

  SELECT a.*,
    b.*,
    c.id, c.ime, c.prezime
    FROM `ugovori-artikli` AS a
    INNER JOIN `ugovori` AS b
    ON a.`ugovor_id` = b.`id`
    INNER JOIN `ids` AS c
    ON b.`kupac_id` = c.`id`
    AND a.`artikal` = ?

希望这对您有所帮助:)

您必须在 SQL 语句中使用别名而不是 table 名称。

SELECT a.*,b.*,c.id, c.ime, c.prezime
FROM `ugovori-artikli` AS a
INNER JOIN `ugovori` AS b ON a.`ugovor_id` = b.`id`
INNER JOIN `ids` AS c
ON b.`kupac_id` = cid`
AND a.`artikal` = ?