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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:15:09+00:00 2026-05-23T00:15:09+00:00

This might be hard to describe in the title, here’s a sample data: id

  • 0

This might be hard to describe in the title, here’s a sample data:

id  pub_type  general_suppl  book_suppl  catalogue_suppl  magazine_suppl
1   book      10             10          0                0
2   book      11             11          0                0
3   catalogue 10             0           10               0
4   magazine  9              0           0                9
5   other     10             0           0                0
6   magazine  8              0           0                10

Each of the item is of a specific publication type with a general supplier and a supplier for the type of publication. other items only have a general_suppl. If I want to get all items on supplier value 10, the following conditions will have to be met:

if pub_type == 'book'
    match on book_suppl == 10
elif pub_type == 'catalogue'
    match on catalogue_suppl == 10
elif pub_type == 'magazine'
    match on magazine_suppl == 10
else
    match on general_suppl == 10

As you can see above, if pub_type falls in book,catalogue,magazine, I ignore the column general_suppl.

The expected output on supplier value 10 will be:

id  pub_type  general_suppl  book_suppl  catalogue_suppl  magazine_suppl
1   book      10             10          0                0
3   catalogue 10             0           10               0
5   other     10             0           0                0
6   magazine  8              0           0                10

I can achieve the above by retrieving all the rows and perform filtering at the code level. Is there a single SQL way to get the above results? The database design and data are beyond my control, so I can’t re-design the DB and will have to work with the above table structure.

  • 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-23T00:15:10+00:00Added an answer on May 23, 2026 at 12:15 am

    It’s ugly, but you can throw that logic into a CASE structure.

    SELECT *
    FROM table
    WHERE 10 = CASE WHEN pub_type = 'book' THEN book_suppl
                    WHEN pub_type = 'catalogue' THEN catalogue_suppl
                    WHEN pub_type = 'magazine' THEN magazine_suppl
                    ELSE general_suppl END
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This might be hard to describe without copying and pasting a ton of code
This might be a little hard to explain, but I will try. I want
This might not be a hard core programming question, but it's related to some
Finding it hard to describe this issue - so please edit if you know
This is a very very... very odd bug. It's hard to describe the exact
This might be a simple question, but I've had a hard time pinning down
Again, apologies for the poor title - very hard to describe. I used the
This might be hard to explain, but I need a way to loop through
This might be hard to show exactly what I'm trying to accomplish, so please
I know this might sound silly but I am finding it hard to understand

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.