简体   繁体   中英

MYSQL PHP: Check already made query for distinct field values?

I have a page that that lists products returned from a mysql query. The query can very greatly depending on many different things.

What I want to do is give the user an option to narrow the current results by series of drop-downs. For example to narrow the product type. But to get the available product types I am currently just checking for distinct values for the product types from the data-base. This is not ideal because if a particular product type is not in any of the current results it will then show no results. So basically I just want to select the distinct values from the current query results and not from the entire data-base.

Is there a way I can do that once the query is already made?

I am looking for something along the lines of:

SELECT DISTINCT product_field FROM (my_other_query)

Thanks!!

当然,只需命名查询即可:

SELECT DISTINCT product_field FROM (SELECT * FROM table1 JOIN ... WHERE ...) oq

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM