Question

I have two tables. The first is called: Computers_F3. The second is a temporary table called "Advice".

I would like to select a value from the 'ProductImage' column of the Computers_F3 table. Which value I want to select, depends on which 'ProductID' is the first value in the 'Advice' table.

http://www.a-training.nl/test/illustratie.png

Is there a way to do this in one mysqli_query? The advice table is already sorted based on the score column. So I would just like to take the first value and use that to select a image from 'productimage'.

Hope you guys can help.

Was it helpful?

Solution

Try this:

SELECT ProductID,ProductImage
FROM Computers_F3 
WHERE ProductID=(SELECT ProductID
                 FROM Advice
                 ORDER BY Score DESC
                 LIMIT 1)

OR using JOIN:

SELECT T1.ProductID,T1.ProductImage
FROM Computers_F3 T1 JOIN
     Advice T2 ON T2.ProductID=T1.ProductID
ORDER BY T2.Score DESC
LIMIT 1
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top