Assume a dating-site-like web application wherein each profile can have one or more users. Each user, say, has the following columns: name, age, gender.
I think the DB design would be something like the following:
TABLE profile
=============================
| profile_id | name |
=============================
| 1 | Dynamic Duo |
-----------------------------
TABLE user
================================================
| user_id | profile_id | name | age | gender |
================================================
| 1 | 1 | Batman | 35 | Male |
------------------------------------------------
| 2 | 1 | Robin | 25 | Male |
------------------------------------------------
Is the DB design good? How would I query for the following:
- Find all profiles where user’s gender=Male
- Find all profiles where user’s genders are Male and Female
- Find all profiles where user’s genders are Male and Female AND each user’s age is > 20 and < 40
- Find all profiles where there are more than 2 associated users
If the DB design can’t support such queries, what design would?
I gave the gender attribute the type of bit.
The first one would be;
Second;
Third is similar, just add
AND u.age > 20 AND u.age < 40to both subqueries.Fourth;