user4431744
user4431744

Reputation:

sqlite: How can results be made unique according to a column

Currently, the following sqlite query returns 45 records. I know that only 4 albums exist. How can the query be made to return only those records that are unique to albumTable.album.

Pseudo Code: where albumTable.album is UNIQUE

    query = new StringBuilder();
    query.append("select albumTable.album, artistTable.artist, songTable.filepath ");
    query.append("from albumTable ");
    query.append("inner join artistTable ");
    query.append("on albumTable.artistID = artistTable.artistID ");
    query.append("inner join songTable ");
    query.append("on albumTable.albumID = songTable.albumID ");

Upvotes: 0

Views: 35

Answers (1)

Iulia Barbu
Iulia Barbu

Reputation: 1530

Use DISTINCT for the selection.

For more info: http://www.tutorialspoint.com/sqlite/sqlite_distinct_keyword.htm

EDIT: Maybe you can select with distinct from the current result. Something like this:

SELECT DISTINCT albumTable.album  
FROM (SELECT albumTable.album,
    artistTable.artist, songTable.filepath  from albumTable 
    inner join artistTable on albumTable.artistID = artistTable.artistID 
    inner join songTable on albumTable.albumID = songTable.albumID )

I don't have such database to test the query ...

Upvotes: 1

Related Questions