#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    2
    Rep Power
    0

    Join Commands


    Hi, I am using Sqlite, and I have two databases, one named Books, the other named BooksCategories,

    Can someone please help me with the code to return the Title and CategoryID of each book from the Books and BookCategories tables?
  2. #2
  3. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Location
    Toronto Canada
    Posts
    27,150
    Rep Power
    4274
    Code:
    SELECT books.title
         , bookscategories.categoryid
      FROM books
    INNER
      JOIN bookscategories
        ON bookscategories.bookid = books.id
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    2
    Rep Power
    0

    UNION Command


    Hi, if I have the tables Books, Publisher, and BookCategories,

    can you join together the Books, Publisher and BookCategories tables using UNION? Assuming we only want to return the PublisherID and CategoryID fields from the latter two tables.
  6. #4
  7. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Location
    Toronto Canada
    Posts
    27,150
    Rep Power
    4274
    Originally Posted by nav505
    can you join together the Books, Publisher and BookCategories tables using UNION?
    no

    use JOIN, like in the example i gave you for your first question above
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

IMN logo majestic logo spyfu logo threadwatch logo seochat tools logo