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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T05:57:24+00:00 2026-05-11T05:57:24+00:00

I’ve got a problem that keeps coming up with normalized databases and was looking

  • 0

I’ve got a problem that keeps coming up with normalized databases and was looking for the best solution.

Suppose I’ve got an album information database. I want to setup the schema in a normalized fashion, so I setup two tables – albums, which has one listing for each album, and songs, which lists all songs contained by albums.

albums ------ aid name  songs ----- aid sid length 

This setup is good for storing the data in a normalized fashion, as an album can contain any number of songs. However, accessing the data in an intuitive manner has now become a lot more difficult. A query which only grabs the information on a single album is simple, but how do you grab multiple albums at once in a single query?

Thus far, the best answer I have come up with is grouping by aid and converting the songs information as arrays. For example, the result would look something like this:

aid, sids,      lengths 1,   [1, 2],    [1:04, 5:45] 2,   [3, 4, 5], [3:30, 4:30, 5:30] 

When I want to work with the data, I have to then parse the sids and lengths, which seems a pointless exercise: I’m making the db concatenate a bunch of values just to separate them later.

My question: What is the best way to access a database with this sort of schema? Am I stuck with multiple arrays? Should I store the entirety of a song’s information in an object and then those songs into a single array, instead of having multiple arrays? Or is there a way of adding an arbitrary number of columns to the resultset (sort of an infinite-join), to accommodate N number of songs? I’m open to any ideas on how to best access the data.

I’m also concerned about efficiency, as these queries will be run often.

If it makes any difference, I’m using a PostgreSQL db along with a PHP front-end.

  • 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. 2026-05-11T05:57:25+00:00Added an answer on May 11, 2026 at 5:57 am

    I have difficulty seeing your point. What exactly do you mean by ‘how do you grab multiple albums at once in a single query’? What exactly do you have difficulties with?

    Intuitively I would say:

    SELECT   a.aid    album_id,   a.name   album_name,   s.sid    song_id,   s.name   song_name,   s.length song_length FROM   albums a   INNER JOIN songs s ON a.aid = s.aid WHERE   a.aid IN (1, 2, 3) 

    and

    SELECT   a.aid         album_id,   a.name        album_name,   COUNT(s.sid)  count_songs,   SUM(s.length) sum_length   /* assuming you store an integer seconds value  */ FROM                         /* here, not a string containing '3:18' or such */   albums a   INNER JOIN songs s ON a.aid = s.aid WHERE   a.aid IN (1, 2, 3) GROUP BY   a.aid 

    Depending on what you want to know/display. Either you query the database for aggregate information, or you calculate it yourself out of the query result #1 in your app.

    Depending on how much data is cached in your app, and how long queries take the one strategy can be faster than the other. I would recommend querying the DB, though. DBs are made for this kind of stuff.

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

Sidebar

Ask A Question

Stats

  • Questions 200k
  • Answers 200k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The sysjobs, sysjobsschedule and sysschedules tables in SQL Server does… May 12, 2026 at 7:54 pm
  • Editorial Team
    Editorial Team added an answer $('div.sep > div').each(function() { if($(this).text() == 'RIGHT') { if($(this).next('div').text() ==… May 12, 2026 at 7:54 pm
  • Editorial Team
    Editorial Team added an answer Sorting in DataGridView doesn't work by default, unless your source… May 12, 2026 at 7:54 pm

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a French site that I want to parse, but am running into
I have text I am displaying in SIlverlight that is coming from a CMS
I am currently running into a problem where an element is coming back from

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.