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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T03:07:46+00:00 2026-06-04T03:07:46+00:00

i have two tables for example users ———————————- id | name | blah ———————————-

  • 0

i have two tables for example

users

----------------------------------
id  | name | blah
----------------------------------
1   | Samy | stackoverflow
2   | jhon | some thing
----------------------------------

skills

---------------------------------------
id | user_id | skill_title | level
---------------------------------------
1  | 1       | php         | good
2  | 1       | css         | excellent
3  | 1       | photoshop   | fair
4  | 2       | php         | good
---------------------------------------

and i run query like this

SELECT * FROM users 
INNER JOIN skills ON users.id = skills.user_id
WHERE ($skill_title[0] LIKE 'skills_title' AND 
       $skill_title[1] LIKE 'skills_title')

where $skill_title is an array
what i need is to select user who have all this skills ie PHP,CSS
if i did query like above it will never bring data because it compare every single record to all array element AND if i replaced and with Or it will work but it will no’t bring user with all skills

any ideas ?

  • 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-06-04T03:07:48+00:00Added an answer on June 4, 2026 at 3:07 am

    @joeshmo’s answer is probably your best solution, but it might be worth giving this a try as well. It might be faster if you have a ton of users, but very few that have the skill you’re looking for:

    SELECT * FROM users
    WHERE
        id IN (SELECT user_id FROM skills WHERE skill_title = '$skills[0]')
        AND id IN (SELECT user_id FROM skills WHERE skill_title = '$skills[1]')
        ...
    

    And your PHP script might look like this:

    $skills = array("php", "css", ... ); // replace ... with the skills you are looking for
    $whereClause = array();
    for ($i=0, $count=count($skills); $i < $count; $i++)
        $whereClause[] = "id IN (SELECT user_id FROM skills WHERE skill_title = '{$skills[$i]}')";
    
    $query = "SELECT * FROM users". (count($whereClause) > 0 ? " WHERE ". implode(" AND ", $whereClause) : "");
    

    Another possible solution would be to use multiple INNER JOINs, as @joeshmo suggested. You might be able to make it a bit smaller and cleaner by doing this:

    SELECT *
    FROM
        users u
        INNER JOIN skills s1 ON u.id = s1.user_id AND s1.skill_title = '$skills[0]'
        INNER JOIN skills s2 ON u.id = s2.user_id AND s2.skill_title = '$skills[1]'
        ...
    

    So your PHP script might look something like this:

    $skills = array("php", "css", ... );
    $joins = array();
    for ($i=0, $count=count($skills); $i < $count; $i++)
        $joins[] = "INNER JOIN skills s{$i} ON u.id = s{$i}.user_id AND s{$i}.skill_title = '{$skills[$i]}'";
    
    $query = "SELECT * FROM users u ". implode(" ", $joins);
    

    I would try both solutions to see which one performs better for your data set.

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

Sidebar

Related Questions

I have two tables Users (name, email, password, instance_id, etc...) example: james bond, james@abc.com,
I have two tables, for example: Table A Table B ======= ======= Name |
I want to have two different tables in MS SQL, for example users and
I have two tables on MySQL, with this structure: Users: id | name Accounts:
Let's put an easy example with two tables: USERS (Id, Name, City) PLAYERS (Id_Player,
I have these two database tables: locations id name users id location_id last_name first_name
We have two tables: -- users -- id name borrower -- ------ -------- 1
In my model, I have two tables with a 1:0..1 relationship between them: (Example
Say for example, I have the following two tables: TableA { _id } TableB
I have two tables, Users and TempUsers and I need to do operations on

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.