我有两张桌子:
CUSTOMERS
id company frontname
PROJECT
id customer_id
我想要做的是搜索客户,然后返回一个项目。谁可以帮我解决这个问题?
答案 0 :(得分:1)
当您加入2个表并添加where
条件时,您可以获得客户的所有项目
select p.*
from project p
inner join customer c on c.id = p.customer_id
where c.frontname = 'customer name'
答案 1 :(得分:0)
SELECT * FROM PROJECT WHERE customer_id = yourvalue
或者如果您需要查询customer表中的值,只需进行连接。
SELECT * FROM Project p
JOIN CUSTOMER c on P.customer_id = c.id
WHERE c.company = 'CompanyName'