Arjun K P
Arjun K P

Reputation: 2111

mysql join or select where tablename1.col1 = tablename2.col1

i have two tables implemented in mysql...

          id            name               password

           1            name1              password1
           2            name2              password2

AND

          id            age               address

           1            age1              address1
           2            age2              address2

Now i need the result of select query in the combined form

          id     name      password    age   address

          1      ....      ........     ...  .....  
          2      ....       .. ..  .    ..   ... ..

Now i tried it using two queries as follows...

SELECT * FROM table1, table2 WHERE table1.id=table2.id;

AND also i tried

SELECT * FROM table1 INNER JOIN table2 ON table1.id = table2.id;

I did got the result as i wanted... But I just wanna know which method is comparitively better taking into fact the no of the columns or data entries...???

Upvotes: 1

Views: 113

Answers (3)

Sergey Eremin
Sergey Eremin

Reputation: 11076

What is "better"? Both methods are valid and should be the same in speed. But knowing that name, password, age and address are all properties of one person, it would be logical to store these values in one table...

Upvotes: 0

Kevin Brey
Kevin Brey

Reputation: 1253

The most efficient way would be to have a single table. There is no reason that I see to break it up like that

Upvotes: 0

Matchu
Matchu

Reputation: 85852

By a previous StackOverflow question, it would seem that performance is often approximately equivalent. Try running EXPLAIN on each of these queries to see which runs better on your dataset—though it's quite possible that MySQL will follow the same process for each.

Upvotes: 2

Related Questions