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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:11:14+00:00 2026-06-06T19:11:14+00:00

I have this sql that is made by help of others. $sql = select

  • 0

I have this sql that is made by help of others.

$sql ="
select e.*, i.*, group_concat( t.tag separator ',') as tag_list
from nv_entries e
JOIN nv_tags t on t.entrie_id = e.id
LEFT JOIN nv_images i on i.entrie_id = e.id

where t.tag in ( $tag_list )
group  by e.id
having count(t.id) = $num_tags ";

The result is this (i only show one entrie here, could be more):

[1] => Array
        (
            [id] => 2
            [band] => Kids for Cash
            [album] => No More Walls E.P.
            [label] => 
            [year] => 1986
            [text] => Text about album kids for cash.
            [entrie_id] => 2
            [source] => img02_9lch1.png
            [tag_list] => tree
        )

For the tags, i have to show all tags that a entrie has and highlight the tags that where used to get the result. In this case [tag_list] => tree only shows one tag, the one that was used in the search field. My question is, how can i get a result like this?:

            ...
            [tag_list] => tree, green, foo, bar
            [used_tags] => tree
        )

As a array is also good, but then please also an array when it’s just one item.

  • 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-06T19:11:15+00:00Added an answer on June 6, 2026 at 7:11 pm

    If I understood correctly use >= in the having condition

    $sql ="
    select e.*, i.*, group_concat( t.tag separator ',') as tag_list
    from nv_entries e
    LEFT JOIN nv_images i on i.entrie_id = e.id
    JOIN nv_tags t on t.entrie_id = e.id
    
    where t.tag in ( $tag_list )
    group  by e.id
    having count(t.id) >= $num_tags ";
    

    ADD

    subquery approach:

    $sql ="
    select e.*, i.*, group_concat( t.tag separator ',') as tag_list
    from nv_entries e
    JOIN nv_tags t on t.entrie_id in (
    select se.id 
    from nv_entries se
    JOIN nv_tags st on st.entrie_id = se.id
    
    where st.tag in ( $tag_list )
    
    group  by se.id
    having count(st.id) >= $num_tags
    
    )
        LEFT JOIN nv_images i on i.entrie_id = e.id
        WHERE 1
        group by e.id
     ";
    

    Into subquery I get the ID list of entrie havin at least requested tags, then in main query I get all infox

    ADD fixed query (see asker comment)

    subquery approach, fix the lost join between “e” and “t” :

    $sql ="
    select e.*, i.*, group_concat( t.tag separator ',') as tag_list
    from nv_entries e
    JOIN nv_tags t on t.entrie_id = e.id 
        LEFT JOIN nv_images i on i.entrie_id = e.id
        WHERE e.id in  (
    select se.id 
    from nv_entries se
    JOIN nv_tags st on st.entrie_id = se.id
    
    where st.tag in ( $tag_list )
    
    group  by se.id
    having count(st.id) >= $num_tags
    
    )
        group by e.id
     ";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this SQL Query that pulls data from 3 tables. I am unable
I have a stored procedure that has this line: SET @SQL = 'SELECT path,title,tags
I currently have this sql statement that I wrote and it works but it's
I have a custom SQL query that I run with this line: @avg_score =
I have a sql statement that uses Difference => http://msdn.microsoft.com/en-us/library/ms188753.aspx I do this in
Hi there I have an SQL table that looks like this: CREATE TABLE IF
I have a line in my SQL Stored Procedure that looks like this (works
I have a SQL query in my ASP.net web app that looks like this:
I have written a SQL Server stored procedure that includes a DateTime parameter. This
I have a select from (nothing to complex) Select * from VIEW This view

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.