Saturday, 15 January 2011

mysql - How to use result set from one query in second query on same table -


I need to query a table once to get the ID number based on any condition, Need to use ID numbers Recover another set of values, all on the same table. Here is the first query:

  to ih_postmeta where meta_key = '_dd_discount_uses' and meta_value & gt; post_id; '0'   

This works fine to recover numbers from post_id where ih_postmeta where post_id = '1088' and meta_key = '_add_discount_code'

This works

  select meta_value: Now I need to run this question equally, except for the first time I loop through the values ​​received from the query Needs to be enabled and not  ou post_id =  hard-coded.  

Here is a sample from the table in question for a particular post_id :

  | Meta_id | Post_ id | Meta_key | Meta_value | 1822 | 1088 | _edd_discount_uses | 8 | 1823 | 1088 | _dd_discount_code | Ls100    

You can use it with a subquery to get what you want :

  select meta_value from ih_postmeta Where in post_id (ih_postmeta chosen by meta_key = '_dd_discount_uses' and meta_value & gt; post_id; '0') and meta_key = '_de_discount_code'    

No comments:

Post a Comment