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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T02:46:52+00:00 2026-05-21T02:46:52+00:00

im not sure if what I am asking for is possible… but it probably

  • 0

im not sure if what I am asking for is possible… but it probably is lol.

Basically, I have two tables, tracks and albums.

I want to display a list of all tracks and get the name from the albums part.

The tables look like this:

tbl_tracks
id - int, auto increment, primary key
album_id - int
title - varchar 50

and

tbl_albums
id - int, auto increment, primary key
title - varchar 50

Now, i run the query:

SELECT tbl_tracks.title, tbl_albums.title FROM tbl_tracks, tbl_albums WHERE tbl_tracks.album_id = tbl_albums.id GROUP BY tbl_tracks.title

Now that prints out the following list:

Track1 Artist1
Track2 Artist1
Track3 Artist1
Track1 Artist2

etc..etc..

(The track names arnt as posted i did that for clarity sake)

Now what i want to do is select another column that numbers each track by artist so the above query would output:

1 Track1 Artist1
2 Track2 Artist1
3 Track3 Artist1
1 Track1 Artist2

But i want to do that without any other columns added to the database or without any serverside loops, how would i do this?

  • 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-21T02:46:54+00:00Added an answer on May 21, 2026 at 2:46 am
    SELECT @rn := if(@g = tbl_albums.id, @rn+1, 1) rownumber,
           tbl_tracks.title, tbl_albums.title,
      @g := tbl_albums.id
    FROM (select @g:=null, @rn:=0) initvars
    CROSS JOIN tbl_tracks
    INNER JOIN tbl_albums on tbl_tracks.album_id = tbl_albums.id
    ORDER BY tbl_albums.id, tbl_tracks.title;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm not sure if what I'm asking is possible at all, but since python
I'm not sure whether I'm asking the question correctly, but I've been told SQL
I'm not sure if what I'm asking is possible. You know how when you
I'm not sure I'm asking the right question here, but I'm looking to provide
Not sure if this is possible with a regular expression replace command, but I
I'm not sure if I have the jargon for asking this question not being
I'm not sure whether it's possible or even making sense so I'm asking here.
I am not sure if I am asking the right question. But is it
Not sure if this is the right stack to be asking this question, but
Not sure if this is possible or if I'm expressing correctly what I'm looking

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.