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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:20:12+00:00 2026-05-28T19:20:12+00:00

So I have a table with columns: deck_id, card_name, quantity, board(irrelevent for this question)

  • 0

So I have a table with columns:

deck_id, card_name, quantity, board(irrelevent for this question)

Each row has a deck id which is what I need, a card name, and amount of aforementioned cards.

It would look something like this:

101, "cardofblahblah", 3, "main"
101, "differentcard", 2, "main"
102, "cardofblahblah", 1, "main"
102, "fictionalcard", 3, "main"
102, "madeupcard", 4, "main"
103, "magicalcard", 2, "main"
103, "trickcard", 3, "main"
...
...

So that’s what my database looks like. What I need is a select query that will return a deck id of a deck which contains all the cards I specify, for example: I need a deck which contains 1 copy of “madeupcard”, and 3 copies of “cardofblahblah”. That’s what I really need done, but it would be great if someone would also mention how I can do > or < instead of only just setting the amount.

I know how to do the queries, but writing a complex one like this has me stumped.

Thanks for any help you guys can offer.’

EDIT:
Just to clarify, I’m looking for deck id’s of decks that contain ALL cards that I specify. For example, “which decks contain 3 copy of cardofblahblah AND 1 copy of madeupcard?”

Any kind of output where I can get the deck id’s is good. The getting the deck id’s is the primary concern for me.

EDIT2:
I figured out the solution after going through various other topics on SO. However, I may not have the most efficient query, so if someone would improve it, that would be great.

SELECT table1.deck_id, table2.deck_id FROM decklist AS table1 
    JOIN (SELECT * FROM decklist WHERE card_name = "cardofblahblah" AND quantity = 3) 
    AS table2 ON table1.deck_id = table2.deck_id 
    WHERE table1.card_name = "madeupcard" AND quantity = 1;"

EDIT3:
Thanks to Telarian. He gave me a better query.

SELECT  t.deck_id
FROM    decklist t
INNER JOIN  decklist l
    ON  l.deck_id = t.deck_id
WHERE   (t.card_name = "madeupcard" AND t.quantity >= 1)
        AND
        (l.card_name = "cardofblahblah" AND l.quantity >= 3)
  • 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-28T19:20:14+00:00Added an answer on May 28, 2026 at 7:20 pm

    It seems like this is being way over-complicated…

    Won’t the following query give you what you want?

    SELECT  t.deck_id
    FROM    decklist t
        INNER JOIN  decklist l
            ON  l.deck_id = t.deck_id
    WHERE   (t.card_name = "madeupcard" AND t.quantity >= 1)
            AND
            (l.card_name = "cardofblahblah" AND l.quantity >= 3)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a table with columns ID,SUBJECT,BRANCH i have select the rows which satisfies
I have my table columns set like this: likes(id, like_message, timestamp) id is the
I have a table with about 35 million rows. each has about 35 integer
I have a table with columns user_id , time_stamp and activity which I use
I have a table AVUKAT Columns--> HESAP, MUSTERI, AVUKAT This is my delete button
I have table with 3 columns: id (of person), city (which person visited) and
I have table with 2 columns: id and name. need trigger which at change
I have a table columns Id and EmployeeID. The table data has the following
absolute newbie here: I have table with columns: resource, resource_type_field, value. I have this
I have table which contains columns like SiteID (identity_Col) SiteName POrderID Location Address Cluster

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.