-1

I have 2 tables in my bd how can i do a query that joins the values of this 2 tables where id of table A is equal to Id_TABa:

Table A:

id

nome

correio

Table B:

Id_TABa

id

nome

  • I recommend reading up on your JOIN syntax, in general. It sounds like you're at the stage where you'd learn more from tutorials than from asking questions here. – Josh from Qaribou May 11 '14 at 23:56

2 Answers2

1
SELECT * FROM tablea INNER JOIN tableb ON (tablea.id = tableb.Id_TABa);
Josh from Qaribou
  • 6,776
  • 2
  • 23
  • 21
1

There are several options :

SELECT *
FROM tableA
INNER JOIN tableB
    ON tableA.id = tableB.id_TABa;

OR

SELECT *
FROM tableA, tableB
WHERE tableA.id = tableB.id_TABa;

The first one is faster (as far as i remember)

Anthony Raymond
  • 7,434
  • 6
  • 42
  • 59
  • It's 'often' faster. The 'inner join' is the ansi-standard way to do it. Most of the time, a query optimizer will step in and execute an equivalent query, but that's not always the case. INNER JOIN is preferred mostly for readability and standards compliance (long WHERE conditions can get unreadable very fast.) – Josh from Qaribou May 12 '14 at 00:03
  • @JoshfromQaribou thanks for the clarification :) i apreciate ;) – Anthony Raymond May 12 '14 at 00:05