Can't figure this out

Discussion in 'MySQL' started by passingTime, Jun 21, 2012.

  1. #1
    I have been trying to learn sql but am struggling. I have a lot of respect for u guys that are good at handling data.

    I've been trying to use one record for more than one row. Hard to explain, hopefully this will make sense:

    table 1

    A B
    1 1

    -------
    table 2

    id name
    1 test

    -----------

    SELECT table2.C AS A, table2.C AS B FROM table1, table2 WHERE (table2.id=table1.A) AND (table2.id=table1.B)


    I am struggling so much with this. Please help.
     
    Solved! View solution.
    passingTime, Jun 21, 2012 IP
  2. #2
    First of, I would explicitly state your JOIN instead of putting it in the where clause. I think you're confused about the table2.C AS A and table2.C AS B. Are you trying to select the name from table 2, or something else? These don't make sense as written.

    SELECT table2.name
    FROM table1
    INNER JOIN table2 ON (table1.A = table2.id AND table1.B = table2.id)
     
    jestep, Jun 22, 2012 IP
  3. passingTime

    passingTime Peon

    Messages:
    49
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    thank u for taking the time to help me out. I learned a lot from ur post :). Much love.

    Yeh sorry i made a mistake but u still figured it out nice one.
     
    passingTime, Jun 22, 2012 IP