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 6750741
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:50:39+00:00 2026-05-26T12:50:39+00:00

I have a table profile_data , structured like this: id, user_id, field_id, value I

  • 0

I have a table profile_data, structured like this:

id, user_id, field_id, value

I need to get user_id for any users that have a match one of several zipcodes and their country is United States.

So far I have this non-working query:

SELECT data1.user_id 
  FROM profile_data data1, profile_data data2 
 WHERE data1.field_id = 80
   AND ( value = '94114' OR value = '94146' OR value = '94117' )
   AND data2.field_id = 90
   AND value = 'United States'
  • 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-26T12:50:40+00:00Added an answer on May 26, 2026 at 12:50 pm

    Here’s my take on what you might be trying to do:

    SELECT user_id
    FROM profile_data
    WHERE (field_id = 80 AND value IN ('94114', '94146', '94117'))
    OR (field_id = 90 AND value = 'United States')
    

    EDIT

    I’m sorry, I didn’t realize that there might be multiple rows per user. If that is the case then the above won’t work. The edited exists statement in the answer above will. although you don’t need to do both as subqueries:

     SELECT user_id FROM profile_data p1
     WHERE (field_id = 80 AND value IN ('94114', '94146', '94117'))
     AND EXISTS (SELECT 1 FROM profile_data p2 WHERE field_id = 90 AND value = 'United States' AND p1.user_id = p2.user_id)
    

    Hopefully your optimizer will reduce it to the correct number of joins anyway.

    As an aside, zip codes are country-specific. So this specific example is redundant, but there are plenty of valid use-cases.

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

Sidebar

Related Questions

I have table with some fields that the value will be 1 0. This
I have table with 50 entries (users with such details like Name Surname Location
I have my table schema and data something like this CompanyCategoryId SubCategoryId CategoryId CompanyId
using php and mysql I have two tables, a users table and a profiles
I have a table create table Profiles (id int, xml_data xml ) that has
I currently have an application that gets hit with over 20,000 users daily and
I have a profile page (less than 10k users) and I need to track
We frequently have users that create multiple accounts and then end up storing the
I have the following tables in MySQL: users profile rates In the users table,
I have a table User that stores user information - such as name, date

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.