我有以下三个sql表。我正在尝试运行一个查询,其中任何没有完成状态的项目已完成'显示以下信息:
Information to display
================================
tbl_projects.pid
tbl_projects.type
tbl_projects.priority
tbl_contacts.fname
tbl_contacts.lname
tbl_accounts.name
表格设置如下:
tbl_projects
========================
pid - PK
type
priority
cid - FK
tbl_contacts
========================
cid - PK
fname
lname
aid - FK
tbl_accounts
=========================
aid - pk
name
address
city
state
zip
我尝试使用以下查询,但它一直给我一个关于.aid的错误?有人可以帮我解决这个问题吗?
SQL QUERY BEING USED
============================================
SELECT *
FROM tbl_projects
INNER JOIN tbl_contacts ON
tbl_projects.cid = tbl_contacts.cid
INNER JOIN tbl_contacts.aid = tbl_accounts.aid
WHERE tbl_projects.status != 'completed' ORDER BY tbl_projects.pid ASC
答案 0 :(得分:1)
第二次加入的语法错误。
INNER JOIN tbl_contacts.aid = tbl_accounts.aid
应该是
INNER JOIN tbl_accounts on tbl_accounts.aid = tbl_contacts.aid