I have a following table named [clients] with columns and values as follows:
+--------+-----------+--------------+----------------+
| uid | client_id | client_input | input_value |
+--------+-----------+--------------+----------------+
| 1 | 22 | City | Seattle |
+--------+-----------+--------------+----------------+
| 2 | 45 | City | Ojai |
+--------+-----------+--------------+----------------+
| 3 | 22 | State | OR |
+--------+-----------+--------------+----------------+
| 4 | 45 | State | CA |
+--------+-----------+--------------+----------------+
| 5 | 65 | City | Orlando |
+--------+-----------+--------------+----------------+
| 6 | 74 | State | AB |
+--------+-----------+--------------+----------------+
| 7 | 65 | State | FL |
+--------+-----------+--------------+----------------+
| 8 | 12 | City | Los Angeles |
+--------+-----------+--------------+----------------+
| 9 | 12 | State | CA |
I need PHP/MySql query which would list all the cities present in the input_value column which are located in the state of ‘CA’. Obviously the common identifier is the client_id which is always a match because if client is in ‘Los Angeles’ the same client_id is also in the row which contains the value of ‘CA’ in the input_value column. This table has over 8 million rows and any fast performing equerry is highly appreciated.
My brain fried, deadline approaching, can’t change the table design, need help, please!
Note: This may need some adjustments and could likely be optimized. But it should get you started and cool your brain.