문제

I have these 2 tables

[Products]
ID
CompanyID,
Name,
PartNo,
IDSGroup,
ChartNo

[Company]
ID,
Name,
RegistrationNo,
RegistrationDate

I want to show these columns from tables when user search for a company name:

Company.Name, Product.Name, Product.PartNo, Product.IDSGroup

This search query let me get the CompanyID

Select Company.ID from Company WHERE Company.Name LIKE "$userSearch%" 

Now I want to use Company.ID for this query to get all product

Select * from Products WHERE CompanyID = "id from previous query"
도움이 되었습니까?

해결책

If it's in the same database you can just join the two tables

SELECT
Company.Name, Products.Name, Products.PartNo, Products.IDSGroup
FROM
Company
LEFT JOIN Products
ON Company.ID = Products.CompanyID
WHERE
Company.Name LIKE "$userSearch%"
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top