Ask the Expert

SQL for joining two tables

What is the SQL statement that can be used to join two tables?

    Requires Free Membership to View

You will be joining the two tables on one or more columns. In Oracle, I can code the join operation similar to the following:
SELECT tableA.columnA, tableA.columnB, tableB.columnX, tableB.columnY
FROM tableA, tableB
WHERE tableA.columnA = tableB.columnX AND tableA.columnB = tableB.columnY;
In the same above, the rows from the two tables are joined where ColumnA = ColumnX and ColumnB = ColumnY. You can code any join condition this way. Oracle also supports the ANSI SQL standard join syntax. The above query in ANSI SQL standard would look like the following:
SELECT tableA.columnA, tableA.columnB, tableB.columnX, tableB.columnY
FROM tableA INNER JOIN tableB
ON tableA.columnA = tableB.columnX AND tableA.columnB = tableB.columnY;

This was first published in March 2006

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to: