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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:01:20+00:00 2026-05-26T07:01:20+00:00

I have a search page where I am trying to build a complex search

  • 0

I have a search page where I am trying to build a complex search condition on two tables which look something like:

Users
ID     NAME
1      Paul
2      Remy

…

Profiles
FK_USERS_ID   TOPIC      TOPIC ID
1             language   1
1             language   2
1             expertise  1
1             expertise  2
1             expertise  3
2             language   1
2             language   2

The second table Profiles, lists the “languages” or the “expertises” (among other stuff) of each user, and topic id is a foreign key to another table depending on the topic (if topic is “language”, than topic ID is the ID of a language in the languages table, etc…).

The search needs to find something like where user name LIKE %PAU% and the user “has” language 1 and has language 2 and has expertise 1 and has expertise 2.

Any help would be really appreciated! I am performing a LEFT JOIN on the two tables although I am not sure that is the correct choice. My main problem lies on the “AND”. The same user has to have both languages 1 and 2, and at the same time expertise 1 and 2.

I work in PHP and I usually try to avoid inner SELECTs and even joins, but I think an inner SELECT is imminent here?

  • 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-26T07:01:21+00:00Added an answer on May 26, 2026 at 7:01 am

    You can accomplish this by building a set of users that matches the criterias from your profile tables, something like this:

    SELECT FK_USERS_ID 
    FROM Profiles 
    WHERE topic='x' 
    AND TOPIC_ID IN (1,2) 
    GROUP BY FK_USERS_ID 
    HAVING COUNT(1) = 2
    

    Here you list your users that matches the topics you need. By grouping by the user id and specifying the amount of rows that should be returned, you can effectively say “only those that has x and y in topic z. Just make sure that the COUNT(1) = x has the same number of different TOPIC_IDs to look for.

    You can then query the user table

    SELECT ID 
    FROM Users 
    WHERE name like '%PAU%' 
    AND ID IN (<insert above query here>)
    

    You can also do it in a join and a derived table, but the essence should be explained above.

    EDIT:
    if you are looking for multiple combinations, you can use mysql’s multi-column IN:

    SELECT FK_USERS_ID 
    FROM Profiles 
    WHERE (topic,topic_id) IN (('x',3),('x',5),('y',3),('y',6))
    GROUP BY FK_USERS_ID 
    HAVING COUNT(1) = 4
    

    This will look for uses matching the pairs x-3, x-5, y-3 and y-6.

    You should be able to build the topic-topic_id pairs easily in php and stuffing it into the SQL string, and also just counting the number of pairs you generate into a variable for using for the count(1) number. See http://www.mysqlperformanceblog.com/2008/04/04/multi-column-in-clause-unexpected-mysql-issue/ for performance talk using this approach.

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

Sidebar

Related Questions

Im trying to create a page in which users can search for items on
I'm trying to build a page which will have a scrolling list of Twitter
I have a search page which uses a simple ajax request to get new
I have a search page like <div class=> <input id=search-input type=text class=input-medium search-query span4>
I have a search page where I would like to stop the user entering
I have a search page in which I am searching data by passing multiple
I have the following scenario. I have a search page which is split into
I'm trying to add a search box to my page that will direct users
I have a search result page that I'm trying to layout but I'm having
I have a simple search page with this text input form <form name=assetInput action=assetResult.jsp

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.