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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T23:57:24+00:00 2026-05-16T23:57:24+00:00

I´m net very good in explaining this. But i do my best: I’ve made

  • 0

I´m net very good in explaining this. But i do my best:

I’ve made a tagging tool for people. Some people contains more then 1 tag, and i need to get those but dont know how to write the SQL query for multiple tag inclusion.

I know you can’t write WHERE conditions like this:
LOWER( peoples_tags.tag_id ) = ‘outside’ AND
LOWER( peoples_tags.tag_id ) = ‘summer’

Cause each person result is on his own row and ‘outside’ and ‘summer’ wont be on the same row. So you don’t get any results by using this query.

This is the whole query:
SELECT DISTINCT peoples.*,tags.tag FROM people
JOIN peoples_tags ON peoples_tags.people_id = peoples.id
JOIN tags ON tags.tag = peoples_tags.tag_id AND
LOWER( peoples_tags.tag_id ) = ‘outside’ AND
LOWER( peoples_tags.tag_id ) = ‘summer’

So how do i write a multiple tag SQL condition? Someone knows?
Sorry for my bad english 🙂

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

    You need to use OR instead of AND. Right now your thought process is this: “I need to get rows where the keyword is ‘outside’, and rows where the keyword is ‘summer’, so I need to use AND“. But the way the RDBMS sees it, you want a given row to be returned if the keyword is ‘indoors’ or the keyword is ‘summer’… so what you actually need is OR, not AND.

    EDIT:

    I see what you want to do now. Sorry for not reading more closely before.

    Try this (there is probably a more efficient/scalable way of doing it, but this should work)

    SELECT
        *
    FROM
        people
    WHERE
        EXISTS(
            SELECT
                *
            FROM
                peoples_tags
            WHERE
                peoples_tags.people_id = people.id AND
                peoples_tags.tag_id = 'outside'
        ) AND
        EXISTS(
            SELECT
                *
            FROM
                peoples_tags
            WHERE
                peoples_tags.people_id = people.id AND
                peoples_tags.tag_id = 'summer'
        )
    

    Edit 2:

    Assuming that the combination of tag_id and people_id is a unique key for peoples_tags, the following will also work:

    SELECT
        people.*,
        COUNT(*) AS Co
    FROM
        people
        JOIN peoples_tags ON people.id = peoples_tags.people_id
    WHERE
        peoples_tags.tag_id = 'outside' OR
        peoples_tags.tag_id = 'summer'
    GROUP BY
        people.id
    HAVING
        Co = 2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been working with asp.net MVC and am still not very good at it.
I have found ASP.Net PageMethods very handy and easy to use, but I have
I have a very simple .net application for testing SMTP on .net. But i
I've recently started tinkering with ASP.NET MVC, but this question should apply to classic
I just started with ASP.NET MVC 1.0. I've read through some tutorials but I
I once made a WinForms FTP uploader, and it worked very good. now, I'm
As all of us know, .NET has very good documentation and variable/parameter naming. Oftentimes,
I'm looking for a good introduction/tutorial for XAML. The Silverlight.Net Quickstarts are very good,
http://lv.php.net/manual/en/function.exif-imagetype.php Can anyone give some more information about the rest extension types. About these:
The ASP.NET framework does a very good job of detecting when a file has

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.