php - Selecting data that appears on 2 tables in MySQL -
i’m trying figure out how select data if appears in 2 different tables. here’s table structure:
here clientinfo
table:
-------------------------------------------------- | name | region id | other info | -------------------------------------------------- | bob | 12 | likes cookies | -------------------------------------------------- | joe | 20 | scuba diver | --------------------------------------------------
here regions
table:
---------------------------------------- | location | region id | published | ---------------------------------------- | california | 12 | 1 | ---------------------------------------- | oregon | 4 | 1 | ---------------------------------------- | washington | 8 | 0 | ---------------------------------------- | colorado | 20 | 1 | ----------------------------------------
i want use query make selection via pull down menu selects state if it’s published , client belongs 1 of states.
edit: in rush yesterday, realized didn't make question clear. wanted able have pull down menu of states populated search parameter. based on data above, web page's pull down menu populate pull down menu according states had clients belonged them.
------------------------------ ------------- | choose state search | ▼ | | search | ------------------------------ ------------- | california | | colorado | ------------------------------
how word mysql query statement?
i use exists
:
select r.* regions r r.published = 1 , exists (select 1 clientinfo ci r.region_id = ci.region_id);
Comments
Post a Comment