Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6084833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:34:11+00:00 2026-05-23T11:34:11+00:00

Assume a dating-site-like web application wherein each profile can have one or more users.

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T11:34:11+00:00Added an answer on May 23, 2026 at 11:34 am

    I gave the gender attribute the type of bit.

    The first one would be;

    -- All male
    SELECT * FROM profiles p
      WHERE p.id NOT IN
        (SELECT u.profile_id FROM users u WHERE u.gender != 1);
    

    Second;

    -- Male and female
    SELECT * FROM profiles p
      WHERE p.id IN
        (SELECT u.profile_id FROM users u WHERE u.gender = 1)
        AND p.Id IN
        (SELECT u.profile_id FROM users u WHERE u.gender = 0)
    

    Third is similar, just add AND u.age > 20 AND u.age < 40 to both subqueries.

    Fourth;

    -- Number of associated users above 2
    SELECT *, count(p.id) AS user_count FROM profiles p
      JOIN users u ON p.id = u.profile_id
      GROUP BY p.id HAVING count(u.id) > 2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Assume I have a C# class like this: [XmlRoot(floors)] public class FloorCollection { [XmlElement(floor)]
Assume I have access to a SMB server at IP 1.2.3.4, how can I
Assume I have a application that stores data,gets data and processes data and stores
Assume I have two vectors represented by two arrays of type double , each
Assume I have a code like this: @autoreleasepool { for(int i = 0; i
Assume I have a class like this: public class Foo { public Bar RequiredProperty
Assume I have one matrix with two columns. Every column has thousands of values.
Assume that we have N erlang nodes, running same application. I want to share
Assume you have 3 given tasks. You can run them either using process or
Assume I have a set of numbers like 1,2,3,4,5,6,7 input as a single String

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.