Skip to content

Another way of joining table without JOIN syntax in SQL

28 April 2009

We often use JOIN syntax for joining 2 or more tables in SQL. Such as INNER JOIN, OUTER JOIN, etc. But here I found another way of joining table that much like INNER JOIN, that is by tricking WHERE syntax.

Below is the example of INNER JOIN between table Customer and Member:

SELECT customer.name, member.name
FROM customer INNER JOIN member
     ON customer.member_id = member.id

Here is the magic of using WHERE syntax:

SELECT customer.name, member.name
FROM customer, member
WHERE customer.member_id = member.id

Though the syntax doesn't look shorter enough, but it will be very handy for some SQL statement that joins a lot of tables.

This trick works fine with MySQL and HSQLDB. I haven't tried on another engine yet.

Tell me if i made a mistake. :) thanks

2 Comments

  1. Anthony

    That’s the syntax I used before I get to know about the “JOIN” syntax. Now I use “JOIN” syntax more frequent than the shorter version. But that SQL statement sure does shorten the query.

    Posted on 10-May-09 at 8:54 pm | Permalink
  2. Yeah, each way has its benefit n certain condition to apply.

    Btw, I just recalled that when we were in the same company, u were the first person who taught me about SQL. I think you probably forgot already :P

    Posted on 15-May-09 at 9:08 am | Permalink