query help

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
CrazyJimmy
Forum Commoner
Posts: 34
Joined: Tue Nov 19, 2002 1:40 pm

query help

Post by CrazyJimmy »

Hi,

I have a db with for music collection with 2 tables. One for title information and another table with just tracks. I can get a query to return a title and all the associated tracks but the title is displayed on every line too. Is it possible to display the title once and the associated tracks?
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

It depends on how you script it... And example:

Code: Select all

$result = mysql_query("select a,b from tunes where id = '1'");
 $title = '';
 while ($row = mysql_fetch_array($result)) {
  // check if $title  is set, if not, set it and display it.
  // else, do nothing.
  if (empty($title)) {
    $title = $row[0];
    echo $row[0];
   }
   // display the track...
   echo $row[1];
 }
ericsodt
Forum Commoner
Posts: 51
Joined: Fri Aug 22, 2003 12:12 pm
Location: VA

Re: query help

Post by ericsodt »

Thats a SQL problem... do an outter query to pull back ONE record for the title and its associated tracks(MANY tracks, ONE record title) = OUTTER QUERY.


ie:

select
blah,
blah2
from
oneTable_t a,
2ndTable_t b
where
a.id(+) = b.id

CrazyJimmy wrote:Hi,

I have a db with for music collection with 2 tables. One for title information and another table with just tracks. I can get a query to return a title and all the associated tracks but the title is displayed on every line too. Is it possible to display the title once and the associated tracks?
Post Reply