SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Sep 2004
    Location
    5
    Posts
    72
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    match values under the same column

    Hi,

    I would like to ask how can I match all values I obtained from a query in a new query?

    e.g :
    Task 1
    // first query I use mysql fetch array to obtain all bookID that matches my search.
    e.g : SELECT * FROM `newBooks` WHERE `keyword` = 'computer' AND `new`='Y'

    Task 2
    // how can I get all the bookID fetched from a while loop above and assign it to another new query where I can obtain another value from different table ?
    e.g ; SELECT * FROM `bookAuthor` WHERE `bookID` = 'All the bookID I obtained'

    I can accomplish task 2 with a single query right? Please advise and thanks

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,270
    Mentioned
    60 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by Ronan View Post
    I can accomplish task 2 with a single query right?
    you can accomplish both tasks with a single query
    Code:
    SELECT newbooks.title
         , newbooks.isbn
         , bookAuthor.name
      FROM newBooks 
    INNER
      JOIN bookAuthor
        ON bookAuthor.bookID = newBooks.bookID
     WHERE newBooks.keyword = 'computer' 
       AND newBooks.new = 'Y'
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •