S
S
sdevalex2012-03-25 12:11:15
PostgreSQL
sdevalex, 2012-03-25 12:11:15

Search by relation HasMany

There is a user table users and tables with user properties (user_id, property_id, value)… Is it possible to select users with several specified properties with one query?

U.P. You can select properties by parameters, group them by user_id, and select groups where the number of rows in the groups equals the number of properties to search. But I have another table (almost the same as with properties) and I also need to do a search on it.

U.P. Can make a virtual table in which to glue the other three? with fields like "property_#{id}"... or is that too much?

U.P. So far, I have found solutions to do several JOINs (depending on the number of properties you are looking for). Works, but 6-8 join + 4 join from other tables is not too much?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Melanitsky, 2012-03-25
@Melanitsky

The article helped me figure out the search by properties . Pay attention to the requests

M
michaelarshinov, 2012-03-26
@michaelarshinov

virtual table

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question