Use ANSI Style for MySQL

I prefer to use ANSI style for writing MySQL queries.  When I started working on SQL, I used the old style aka Theta style for all my queries. Example of a query in  Theta style :

SELECT  e.title, i.first_name, i.response

FROM invitees i,

events e

WHERE = i.event_id

AND = ‘2008-07-04’;

which , in ANSI style is equivalent to :

SELECT e.title,, i.response

FROM invitees i

INNER JOIN events e on = i.event_id

WHERE = ‘2008-07-04’

Many developers prefer using the old style. But believe me, ANSI style is lot better and advantageous.

First, MySQL  supports OUTER JOINs in ANSI style. Second, ANSI style forces you to think about your joins  clearly. Your code is lot more readable in ANSI style. For example, all the joins go in the FROM clause, and the WHERE clause is left with only statements which filter out the result set of the tables in the join.  You get a clear picture of how the tables are linked with each other.

For more information on Joins, see Reference below.

Reference : Join Syntax in MySQL

2 thoughts on “0

  1. Hi Shaka,

    I believe there are no advantages on performance if we use ANSI style for SQL. But syntactically it is better.

    There is a general habit of putting table joins (city.country_id = in the WHERE clause along with filter statements like ‘city = “Pune”‘. If we use ANSI style then the join statements are written in the FROM clause and we will have only filter statements in the WHERE clause. Hence it makes the code more readable.

    Also, you can’t do OUTER Joins without using ANSI style.

    So its a good habit of writing SQL statements in ANSI style as early as possible while programming.

Leave a Reply

Your email address will not be published. Required fields are marked *

Previous post Sarkar Raj : No Power At All
Next post ‘EXISTS’ is better than ‘IN’