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

  • Home
  • SEARCH
  • 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 6163601
In Process

The Archive Base Latest Questions

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

The database is not mine. The structure is fid| uid | value 3 |

  • 0

The database is not mine. The structure is

fid| uid | value
 3 |  3  | spain
 3 |  5  | France
 2 |  3  | 45
 6 |  3  | male
 6 |  5  | female
 2 |  5  | 32

The field ID is primary key in another table, I’d like to forget about.
Im trying to find all uid that have values ‘spain’, ‘male’

I have the following working.

SELECT uid 
FROM DATABASE
WHERE value IN ('spain', 'male') GROUP BY uid HAVING COUNT(*) >= 2

The catch is as follows.. How would I select male, spain with value in range of 20-30
(that is males born in spain aged between 20-30?

Thanks a ton!!

  • 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-23T21:51:12+00:00Added an answer on May 23, 2026 at 9:51 pm

    You have a really messed up table. You are mixing unrelated things in value.

    Try:

    SELECT uid
    FROM DATABASE a JOIN
      DATABASE b USING (uid)
    WHERE a.value IN ('spain', 'male')
      AND b.value >= 20
      AND b.value <= 30
    GROUP BY uid
    HAVING COUNT(*) >= 2
    

    Note that I am comparing a string and an integer. You will need to test to see how well that works.

    Also, I just put spain and male together, but perhaps they are really unrelated?

    Does fid determine the type of value?

    Try:

    SELECT uid
    FROM DATABASE country
    JOIN DATABASE gender USING (uid)
    JOIN DATABASE age USING (uid)
    WHERE
      country.fid = 3 AND
      gender.fid = 6 AND
      age.fid = 2 AND
      county.value = 'spain' AND
      gender.value = 'male' AND
      age.value >= 20
      age.value <= 30
    GROUP BY uid
    HAVING COUNT(*) >= 2
    

    This code should work more reliably.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Good Day, I'm currently designing database structure for a website of mine. I need
A friend of mine told me that saving images in the database is not
I have a MS sql database (not server), my program reads file structure from
phpMyAdmin will not allow me to add a new field to my database --
Can we create a new MySQL database( not a table, I want a new
this is a different question concerning: add a connection to database not working, asp.net
I'm using Hibernate for ORM of my Java app to an Oracle database (not
As the post title implies, I have a legacy database (not sure if that
If the database is not Oracle, it is MS SQl 2008. My task: if
I've read in blogs that the database should not be hit when the unit

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.