php - MySql List all items from table 1 where item conditionally exists in table 2Get the solution ↓↓↓
What you want is to start with a distinct list of the
inventory for that distributor. This is our base query (replace the question mark with your actual distributor ID):
SELECT DISTINCT partID FROM inventory WHERE DistID = ?
Then we modify that query to join on the
parts table to pull back the part information:
SELECT DISTINCT i.partID, p.* FROM inventory i INNER JOIN parts p ON i.partID = p.partID WHERE i.DistID = ?
thats not a PHP question at all.
Anyway, if I understood your question your should try this:
SELECT parts.* FROM parts WHERE parts.PartID IN (SELECT invetory.PartID FROM invetory WHERE invetory.DistID = 'wanted_DistID');
You should change 'wanted_DistID' for you wanted DistID. Hope I could help.
Share solution ↓
Link To Answer People are also looking for solutions of the problem: object of class stdclass could not be converted to string
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.