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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T23:18:15+00:00 2026-05-29T23:18:15+00:00

I have this array: $results = array(‘1’, ‘3’, ‘123’) and this table: id |

  • 0

I have this array:

$results = array('1', '3', '123')

and this table:

id  |  item  |  tag
1      1        1
2      1        3
3      1        123
4      2        1
5      3        1
6      4        3

I want to perform a query like this:

SELECT item FROM table WHERE ALL 3 TAGS OF THE ARRAY EXIST.

In the example I want to return only Item=1, because it’s the only Item with all 3 tags of the array.

So far I have this:

$query .= " SELECT item FROM #__table WHERE tag IN ('";
$query .= implode("','",$results); 
$query .= "')"; 

But it does not return the correct Items, instead it returns all items that are related at least with one element of the array.

  • 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-29T23:18:16+00:00Added an answer on May 29, 2026 at 11:18 pm

    To make the IN work as an AND instead of an OR, you use a HAVING clause to make sure that you get the same number of distinct values returned as exist in the IN clause.

    SELECT item
        FROM YourTable
        WHERE tag IN ('1', '3', '123')
        GROUP BY item
        HAVING COUNT(DISTINCT tag) = 3
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have an array like this Array ( [0] => Array ( [s_id] =>
I have an array which looks like this : selected_products[0]=[r1,7up,61,Albertsons] selected_products[1]=[r3, Arrowhead,78,Arrowhead ] selected_products[2]=[r8,
I have an array of folders/files that looks like this: Array ( [Root Folder
I have this FQL: $femail = $facebook->api(array( 'method' => 'fql.query', 'locale' => 'en_US', 'query'
I have this loop in PHP that echoes out a table of results, <table
I have an XML like this <resultGroups> <subGroups> <results> </results> <results> </results> </subGroups> <subGroups>
I have this returned JSON: results: Array[15] 0: Object created_at: Wed, 10 Aug 2011
I have an array that looks like this: Array ( [0] => Array (
I have an PHP array parsed from a JSON string that looks like this:
I'm trying to have this function return multiple results in array(?). So basically instead

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.