WordPress query results where all columns have the same value as column of selected id

I have looked at various results but I am not sure how to make it work. All the examples have different tables to select or the same value based on selected column value.

But I need a different solution, I have an id of the selected item and based on that id I need to get value from column and list all other rows that have the same value as that column of selected id.

Read More
+----+------------------------------+------------+
| id |             name             | country_id |
+----+------------------------------+------------+
| 1  | Andaman and Nicobar Islands  |        101 |
| 2  | Andhra Pradesh               |         95 |
| 3  | Arunachal Pradesh            |        101 |
| 4  | Assam                        |        101 |
| 5  | Bihar                        |         43 |
+----+------------------------------+------------+

So if I have posted $_POST state with id 3 I need to somehow get that state country_id and display all other states with the same country_id so the final list would be

+----+------------------------------+------------+
| id |             name             | country_id |
+----+------------------------------+------------+
| 1  | Andaman and Nicobar Islands  |        101 |
| 3  | Arunachal Pradesh            |        101 |
| 4  | Assam                        |        101 |
+----+------------------------------+------------+

Related posts

1 comment

  1. Following code should do, assuming that id is a unique value

    SELECT * FROM `your_table`
    WHERE `country_id`=(SELECT `country_id` FROM `your_table` WHERE `id`='your_id')
    

Comments are closed.