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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:57:50+00:00 2026-06-11T15:57:50+00:00

In my MySQL database I have two columns setup like this (for example): series_id

  • 0

In my MySQL database I have two columns setup like this (for example):

series_id   category_id
    1            1
    1            2
    1            3
    2            1
    2            3
    3            2
    4            1
    4            2

What is the proper select query I can use to select the series_id when the category_id = 1 and 2?

Current query is this:

SELECT series_id 
FROM table 
WHERE category_id = '1' 
OR category_id = '2' 
GROUP BY series_id"

This does not retrieve any results:

SELECT series_id 
FROM table 
WHERE category_id = '1' 
AND category_id = '2' 
GROUP BY series_id

In regards to this example I would like it to return the two rows where the series_id is 1 and 2 so the result looks like this:

series_id
     1
     4

(Optional / Bonus) If it is possible to come up with another solution or utilize:

GROUP_CONCAT(category_id SEPARATOR ', ') AS category

for the returned series_id (s) from this query so the returned result is:

series_id    category
     1       1, 2, 3
     4       1, 2
  • 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-11T15:57:51+00:00Added an answer on June 11, 2026 at 3:57 pm
    SELECT   series_id
    FROM     my_table
    WHERE    category_id IN (1,2)
    GROUP BY series_id
    HAVING   COUNT(*) = 2
    

    See it on sqlfiddle.

    Note that if (series_id, category_id) are not guaranteed to be unique, you should replace COUNT(*) with the less performant COUNT(DISTINCT category_id).

    To return the grouped results, you can join against your table again:

    SELECT series_id, GROUP_CONCAT(category_id)
    FROM   my_table NATURAL JOIN (
      SELECT   series_id
      FROM     my_table
      WHERE    category_id IN (1,2)
      GROUP BY series_id
      HAVING   COUNT(*) = 2
    ) t
    GROUP BY series_id
    

    See it on sqlfiddle.

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

Sidebar

Related Questions

I have table in MySQL database with two integer columns for example: userid |
So I have two columns of text in a MySQL database, an example would
I have a MySQL database with two tables (simplified for this question): movies table
I have this table in a mysql database: mysql> show columns from wifi_network_config_auth_algorithm; +------------------------+-------------+------+-----+---------+-------+
I have two database columns in a mysql database, A and B. In a
Okay, so let's say I have a mysql database table with two columns, one
I have a MySQL database table with two columns that interest me. Individually they
I have two tables in MYSQL database which contains same Columns by counting and
I have a PHP program w/MySQL database which contains many records. Two columns of
In a MySQL database I have two tables linked in a join. One table

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.