Query help needed

Discussion in 'Databases' started by manilodisan, May 31, 2007.

  1. #1
    After a whole day of work I got stuck into one query which I'm sure it's simple but I can't getthe right result. Maybe I'm tired, I need a light on this.

    I have 2 tables with a relation between them:

    questions (ID, question) and answers (ID, ID_question, visitor_IP).

    each time a visitor enters an answer I store the ip address in order to not show the same question twice. My damn question is:

    How do I select the questions from the first table (questions) that are not answered (the visitor's ip and it's ID are not stored in the answers table.


    Thank you for your help, if any
     
    manilodisan, May 31, 2007 IP
  2. zonzon

    zonzon Peon

    Messages:
    100
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #2
    SELECT q.*
    FROM questions q
    WHERE NOT EXISTS(SELECT * FROM answers a WHERE a.id_question = q.id AND visitor_ip = 'x.x.x.x')
     
    zonzon, May 31, 2007 IP
  3. manilodisan

    manilodisan Peon

    Messages:
    224
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thank you zonzon. That worked like a charm.
     
    manilodisan, May 31, 2007 IP
  4. zonzon

    zonzon Peon

    Messages:
    100
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #4
    and it's o0ptimized! ;) if indexes are optimized!
     
    zonzon, May 31, 2007 IP