query help

Discussion in 'Databases' started by sensoryaddict, Aug 30, 2010.

  1. #1
    Hi

    I am new to php/mysql and I need help with a select statement.

    The database has 2 tables with the same schema

    date, user, symbol

    I basically want to compare both tables and if any "symbol" occur in both tables on the same "date" and by same "user" then I want to return this data/user/symbol.

    Can I do this with a select statement or do I need to process these 2 tables into a 3rd tables and then select the data from there?
     
    sensoryaddict, Aug 30, 2010 IP
  2. koko5

    koko5 Active Member

    Messages:
    394
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    70
    #2
    Hi, try

    
    SELECT * FROM T1 NATURAL JOIN T2;
    
    Code (markup):
    Regards :)
     
    koko5, Aug 30, 2010 IP
  3. Mohie

    Mohie Peon

    Messages:
    122
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #3
    actually that's not accurate enough, because he said "any symbol" and not the same symbol
    so if i understand correctly , he want to check with restriction to date and user and with NO RESTRICTION AT SYMBOL..

    SELECT *
    FROM table1 , table2
    WHERE table1.user=table2.user AND table1.date=table2.date;
     
    Last edited: Aug 31, 2010
    Mohie, Aug 31, 2010 IP
  4. sensoryaddict

    sensoryaddict Peon

    Messages:
    33
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    This worked great, thanks!

    I did mean symbol should match, maybe I wasn't clear. Both examples helped me understand more.
     
    sensoryaddict, Sep 1, 2010 IP
  5. Rajeev123

    Rajeev123 Peon

    Messages:
    100
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    koko5,,

    ya your information is true.!!

    manoj
     
    Rajeev123, Oct 10, 2010 IP
  6. merabasera

    merabasera Peon

    Messages:
    18
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    You are true your query works
     
    merabasera, Oct 12, 2010 IP