morganchees morganchees - 1 year ago 46
PHP Question

Get unique values from sql table where contained ID from row

I have a query like this:

$get_all_brand_auto = mysql_query("SELECT * FROM oc_product WHERE manufacturer_id='$mid'");

As a result, I get the id of certain manufacturers . After that I have to make a request to the oc_product_attribute table to get a unique value "text".

This is table oc_product_attribute:

enter image description here

I need to get unique values ​​of the column "text".

in row should be in the array, which I received earlier

Answer Source

You can do it by one nested query

SELECT DISTINCT text FROM oc_product_attribute WHERE product_id IN (SELECT id FROM oc_product WHERE manufacturer_id='$mid')

By the way, as always, I recommend you to do not use the mysql library. It's deprecated.

Try using mysqli. It's easy to learn