Answered
SQL Query Help - inner joins and distinct results
Hi,
ASP VB, SQL Server
I have a database structure with 3 tables - users, albums and photos. each user has a unique id, each album record has a unique albumid and also contains a column with userid. each photo record has a unique id as well as storing the userid and the album in which the image belongs.
I'm trying to write a query that will return the list of albums for a particular user (based on a userid query string) and which will also bring back the id of the first record in the photo table for each of these albums.
the closest I am getting is to run a query to select albumid from albums where userid=varuserid with an inner join on the photos table to pull out the photo id - problem I then have is that it pulls out every photo from the photos table where userid=varuserid, so when I do a repeat region to display a list of albums for a certain user, it produces a list of all photos where userid=varuserid
I really want it to just return a list of album ids based on the userid variable, but also to return the first record from the photos table for each of these albumids
I've tried various combinations of inner joins, select distinc etc but not joy.
any suggestions would be much appreciated as am floundering here...
ASP VB, SQL Server
I have a database structure with 3 tables - users, albums and photos. each user has a unique id, each album record has a unique albumid and also contains a column with userid. each photo record has a unique id as well as storing the userid and the album in which the image belongs.
I'm trying to write a query that will return the list of albums for a particular user (based on a userid query string) and which will also bring back the id of the first record in the photo table for each of these albums.
the closest I am getting is to run a query to select albumid from albums where userid=varuserid with an inner join on the photos table to pull out the photo id - problem I then have is that it pulls out every photo from the photos table where userid=varuserid, so when I do a repeat region to display a list of albums for a certain user, it produces a list of all photos where userid=varuserid
I really want it to just return a list of album ids based on the userid variable, but also to return the first record from the photos table for each of these albumids
I've tried various combinations of inner joins, select distinc etc but not joy.
any suggestions would be much appreciated as am floundering here...
