SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot maxdream01's Avatar
    Join Date
    Feb 2011
    Location
    USA
    Posts
    149
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    MySQL check if value exists in another table

    Hey Everyone,

    I have three tables, one table, vendors, holds a vendor name and an id, the second table, vendorlinks, has two columns vendorID and pageID, the id in vendors has the same value as vendorID in vendorLinks, and the third table page has the column page id which matches up to pageID in vendorlinks.

    So basically I have a type of multiple pages correspond to multiple vendors system, and I need to display a page that contains all the pages that correspond to the vendor but also have pageIDs that correspond to the pages table pageId column, as not all entries in vendorlink correspond to a particular page entry.

    What I need is a sql statement that will probably look something like this

    'SELECT * FROM VendorLink Where vendorID = :venId And' pageId matches with ID IN pages table

    That last part is what I don't know how to do. Any help is alwaya aprreciated.

    Thanks
    Maxdream01
    PHP is FUN

  2. #2
    SitePoint Zealot maxdream01's Avatar
    Join Date
    Feb 2011
    Location
    USA
    Posts
    149
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nevermind everyone i solved it here's my solution i fanyone is interested:

    'SELECT * FROM VendorLink Where vendorID = :venId AND pageID IN (SELECT id FROM Pages)''
    PHP is FUN

  3. #3
    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 maxdream01 View Post
    here's my solution i fanyone is interested:
    you be missing a table in there
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  4. #4
    SitePoint Zealot maxdream01's Avatar
    Join Date
    Feb 2011
    Location
    USA
    Posts
    149
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh no, im calculating the vendor id with another statement, since there is also other information I need to get from that table.
    PHP is FUN

  5. #5
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,276
    Mentioned
    18 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by maxdream01 View Post
    ...but also have pageIDs that correspond to the pages table pageId column, as not all entries in vendorlink correspond to a particular page entry.
    It's great that you solved your own problem, but I have to admit, this requirement baffles me a bit. How could you have a vendorLink pageID that doesn't correspond to a page entry? Where did the value of the pageID even come from if there's no corresponding page?
    "First make it work. Then make it better."

  6. #6
    SitePoint Zealot maxdream01's Avatar
    Join Date
    Feb 2011
    Location
    USA
    Posts
    149
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Jeff Mott View Post
    It's great that you solved your own problem, but I have to admit, this requirement baffles me a bit. How could you have a vendorLink pageID that doesn't correspond to a page entry? Where did the value of the pageID even come from if there's no corresponding page?
    Users are allowed submit pages which we keep in a seperate tablebefore confirmation, so when we display pages that pertain to a certain vendor we want to make sure there is no evidence of another page linking to that vendor, that we don't show.
    PHP is FUN


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
  •