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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T08:45:42+00:00 2026-05-31T08:45:42+00:00

I need to select the bundle entries from the table below but only if

  • 0

I need to select the “bundle” entries from the table below but only if a bundle exists other wise select track 1 from each release. Each release has a unique “cat_no” which is why I need to use GROUP BY.

SELECT * FROM cds  
WHERE genre='rock'  
GROUP BY cat_no  
ORDER BY ABS(track) DESC  
LIMIT 0,3

This what I have tried but I am sometimes getting track 1 when there is a bundle for that release.

Table

genre cat_no  track  
rock  001     1      
rock  001     2      
rock  001     bundle 
rock  002     1      
rock  002     2      
rock  002     bundle 
rock  003     1     
rock  003     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-05-31T08:45:44+00:00Added an answer on May 31, 2026 at 8:45 am

    Try to sort records before the grouping –

    SELECT * FROM
      (SELECT * FROM cds WHERE genre = 'rock' ORDER BY IF(track = 'bundle', 0, 1)) t
    GROUP BY
      cat_no;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to select and act on a table element with JQuery, but only
I need a select from table which does not have column that tells when
I need to select multiple records I use SELECT * FROM `table` WHERE `ID`
if select * from table where x=1 returns 0 rows, then I need select
this is my code... but i need select only column to display in my
I need to select a bunch of data into a temp table to then
I need to select a datetime column in a table. However, I want the
Following SQL get what I need: SELECT TOP (50) [nodeId] FROM [dbo].[cmsContentXml] WHERE [xml]
I am using GROUP BY to only select one row for all entries that
I have model with ManyToManyField. Now I need form but don't need select field

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.