两个查询和两个内部联接在一起
我这里有两个疑问。
第一个显示了 cat 链接 = 3 的列表。
Select *
from Listings
JOIN Category ON Listings.Category = Category.CategoryID
WHERE Link = '3'
第二个显示了连接到帐户的列表。
SELECT *
FROM Listings
JOIN Accounts ON Listings.Account_ID = Accounts.Account_ID
我的尝试是这样的:
SELECT *
FROM (Select *
from Listings
JOIN Category ON Listings.Category = Category.CategoryID
WHERE Link = '3')
JOIN Accounts ON Listings.Account_ID = Accounts.Account_ID
但这似乎不起作用,有什么解决方案吗?
I have two queries here.
First one shows listings where a cat link = 3.
Select *
from Listings
JOIN Category ON Listings.Category = Category.CategoryID
WHERE Link = '3'
And the second one shows listing connecting to accounts.
SELECT *
FROM Listings
JOIN Accounts ON Listings.Account_ID = Accounts.Account_ID
My try is something like:
SELECT *
FROM (Select *
from Listings
JOIN Category ON Listings.Category = Category.CategoryID
WHERE Link = '3')
JOIN Accounts ON Listings.Account_ID = Accounts.Account_ID
But that doesn't seem to work, any solutions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
WHERE ...
应该位于两个连接之后。您可以使用
SELECT Listings.*
显示 Listing 表中的所有字段,或者使用SELECT *
显示所有 3 个联接表中的所有字段,或者使用SELECT Listings.* , Accounts.*
从这两个表中显示,等等。The
WHERE ...
should go after the two joins.You can have
SELECT Listings.*
to show all fields from table Listing, orSELECT *
to show all fields from all 3 joined tables, orSELECT Listings.*, Accounts.*
to show from these 2 tables, etc.像这样的东西会起作用吗?
您没有指定“Link”位于哪个表中,因此如果您使用此代码(假设它执行您想要的操作),我建议您指定“Link”字段位于哪个表中,如下所示:
WHERE TableName.Link = '3'
Would something like this work?
You didn't specify which table "Link" is in, so if you use this code (provided it does what you want), I'd recommend that you specify which table the "Link" field is in like so:
WHERE TableName.Link = '3'
你能发布错误吗?该错误很可能是告诉您所有表都必须有名称。这意味着您对临时表执行的子选择必须有一个表别名。
Can you post the error? Most likely the error is telling you that all tables must have names. Which means that your subselect that you're doing for a temp table MUST have a table alias.