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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T23:38:35+00:00 2026-06-05T23:38:35+00:00

I store some data in MySQL and want to filter out rows that match

  • 0

I store some data in MySQL and want to filter out rows that match a given criteria.

Sounds easy, but it is not since there are some join criteria involved.

I do have the following tables:

items : id, ...
genres: id, name:varchar, item_id

Each item has multiple genres.

The query should filter out items if at least one genre does match a given genre name (or a set of names).

For example:

Item with id 1 has 3 genres
  - genre name = 'foo'
  - genre name = 'bar'
  - genre name = 'baz'

Item 1 may not be part of the result set if the given genre name is ‘bar’, [‘bar’, ‘baz’, ‘xyz’], etc.

I tried to left join the genres on the items and applied a WHERE statement with “genres.name NOT IN (?)”. ? is the given set of genre names.

This (of course) only works for items with exactly one genre. The same could be achieved by multiple WHERE conditions: WHERE name <> ‘a’ AND name <> ‘b’ …

Any ideas how to get this query done properly?

Thanks in advance!

  • 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-05T23:38:36+00:00Added an answer on June 5, 2026 at 11:38 pm

    You can use a correlated subquery.
    Example:

    SELECT id 
    FROM   items i
    WHERE  NOT EXISTS (SELECT 1 
                       FROM   genres g
                       WHERE  g.`name` = 'bar' 
                       AND    i.id = g.item_id);
    

    A correlated subquery differs from other subqueries in that it references the outer query.
    Correlated subqueries are run for each row projected/selected by the outer query.

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

Sidebar

Related Questions

I want to be able to store (not echo) some data that has been
I want to store some data during my site viewing. Sometime i need to
I want to create a data store to allow me to store some data.
I want to temporary store some mapping data. The mapping is one to one.
I am using ZODB to store some data that exists in memory for the
I want to select some data from db and store in an array. Suppose
I'd like to store some data in Python in a similar form to a
I'd like to store some data in a cookie and my initial though was
In my app i store some data in the device storage. This data is
I'm working on a program where I store some data in an integer and

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.