in

System.Data.SQLite

An open source ADO.NET provider for the SQLite database engine

Join on two tables

Last post 09-14-2007 4:19 AM by Wiaz. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 09-14-2007 1:28 AM

    • ZNS
    • Top 500 Contributor
    • Joined on 09-14-2007
    • Posts 3

    Join on two tables

    Hi. I just started using System.Data.SQLite and really like it. I do however have some trouble with a to me simple query. I have three tables, tblArtist, tblAlbum, tblTrack I guess you can figure out the relations yourself ;) Now I want to select 1 album with it's artist and tracks, so I use the following query

    SELECT tblAlbum.AlbumName, tblAlbum.AlbumReleaseYear, tblTrack.TrackNumber, tblTrack.TrackName, tblTrack.TrackDuration, tblArtist.ArtistName, tblArtist.ArtistId, tblArtist.ArtistGenre
    FROM tblAlbum
    INNER JOIN tblTrack ON tblAlbum.AlbumId = tblTrack.AlbumId
    INNER JOIN tblArtist ON tblAlbum.ArtistId = tblArtist.ArtistId
    WHERE tblAlbum.AlbumId = " + id + " ORDER BY tblTrack.TrackNumber, tblTrack.TrackId ASC

    However this returns nothing, but when I run the query in SQLServer using the same tables and data it returns what I'd expect it to. What am I doing wrong here?

     

    -------------------------

     

    Let me tell you what I'm doing wrong, I'm being stupid. No wonder you get no result when you enter the id from sql server into sqlite. Sorry for the post.

    Filed under:
  • 09-14-2007 4:19 AM In reply to

    • Wiaz
    • Top 10 Contributor
    • Joined on 01-11-2007
    • Poland
    • Posts 47

    Re: Join on two tables

    try this: SELECT tblAlbum.AlbumName, tblAlbum.AlbumReleaseYear, tblTrack.TrackNumber, tblTrack.TrackName, tblTrack.TrackDuration, tblArtist.ArtistName, tblArtist.ArtistId, tblArtist.ArtistGenre FROM tblTrack LEFT OUTER JOIN tblAlbum ON tblAlbum.AlbumId = tblTrack.AlbumId LEFT OUTER tblArtist ON tblAlbum.ArtistId = tblArtist.ArtistId WHERE tblAlbum.AlbumId = " + id + " ORDER BY tblTrack.TrackNumber, tblTrack.TrackId ASC notice that I swap order tblAlbum and tblTrack in JOIN and i dont know: WHERE tblAlbum.AlbumId = " + id + " ?? i think the best (if it is parameter) it would be : WHERE tblAlbum.AlbumId = @albumid i hope it will helps
    Wiaz
Page 1 of 1 (2 items)
Powered by Community Server (Commercial Edition), by Telligent Systems