What I’m trying to do is set up a query that calls from a Database (the Chinook database in particular – http://chinookdatabase.codeplex.com/)
Now, in order to display the query output correctly, I need to join multiple tables – each that share similar column names. With the Chinook database, there are multiple tables (Artist, Album, Genre, Media Type, Track, etc.). Let’s say I’m trying to display the contents of an Artist’s Name with:
public function fetchArtistName(){
return $row['Name'];
}
This is very ambiguous since this row would go and find the Name field for Media Type or Album Name before it finds the artist name.
My SQL statement is as follows:
SELECT *
FROM track AS t
LEFT JOIN album al
ON t.AlbumId = al.AlbumId
LEFT JOIN artist ar ON al.ArtistId = ar.ArtistId
LEFT JOIN mediatype m ON t.MediaTypeId = m.MediaTypeId
LIMIT 0,15;
Is there a way I could go about changing the table that is outputted to be like
| t.Name | al.Name | ar.Name | m.name |
so that I could essentially call these much easier with
public function fetchArtistName(){
return $row['ar.Name'];
}
It has been so long since I’ve played with SQL and I’m really stuck. Any help would be greatly appreciated, I’ve Googled and search here already.
Thank you.
I’m not sure that you can do this with
SELECT *.... You’d need to do something like:…such that your PHP function is defined as