MySQL复杂连接-Can';t在第二个表中选择多列

MySQL复杂连接-Can';t在第二个表中选择多列,mysql,join,Mysql,Join,我不明白为什么不能在第二个表中选择多个列。这是我的桌子: Computers: ---------- id, cond, type Images: ------- id, foreignid, name, width, height, def 以下是我的选择声明: SELECT id, cond, type, (SELECT name, width, height FROM images WHERE foreignid = computers.id ORDER BY def

我不明白为什么不能在第二个表中选择多个列。这是我的桌子:

Computers:
----------
id, cond, type

Images:
-------
id, foreignid, name, width, height, def
以下是我的选择声明:

SELECT
    id, cond, type,
    (SELECT name, width, height FROM images WHERE foreignid = computers.id ORDER BY def DESC LIMIT 1) AS image
FROM computers
这就是我得到的错误:

Operand should contain 1 column(s)

你想做这样的事吗

select c.id, c.cond, c.type, i.name, i.width, i.height from computers c
left join images i on i.foreignid=c.id
order by i.def desc limit 1
编辑: 但是join子句取决于您到底想要什么。 如果你想要所有的计算机,它们是否有图像

computers left join images
computers right join images
如果您想要所有图像,请选择是否使用计算机

computers left join images
computers right join images
如果您只需要具有图像的计算机和具有图像的计算机,请使用

computers inner join images
如果希望所有计算机和所有图像都使用

computer outer join images

将返回一台计算机及其相关图像(如果这是您要查找的图像)。

我需要所有计算机和一个图像,其中有默认图像(def列,如果是1),然后使用我文章的第一条语句。谢谢,我添加了I.foreignid=c.id和I.def>0并删除了limit语句以完成查询。再次堆叠溢出FTW。