goromlagche
goromlagche

Reputation: 442

Mysql queries for through tables

Basically I have two tables,

  1. Groups: with fields like location, city, country
  2. Property Type : with fields like 1BHK, 2BHK, 3BHK
  3. Group_property_type : which is basically a through table with foreign key group_id and property_type_id

Now I want to add a exhaustive search function. which will take both the fields of groups table and property_type table. Any help with the SQL query?

I am using mysql

Upvotes: 0

Views: 41

Answers (1)

Ganesh Jadhav
Ganesh Jadhav

Reputation: 2848

SELECT  *
FROM    Group_property_type GPT
JOIN    Groups G
    ON  GPT.group_id = G.group_id
JOIN    PropertyType PT
    ON  GPT.property_type_id = PT.property_type_id
WHERE   G.location LIKE '%' + @searchstring + '%'
    OR  G.city LIKE '%' + @searchstring + '%'
    OR  ...

Upvotes: 1

Related Questions