converting joins from oracle to mysql

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

I have to run the following statement in MySQL. (The script is
generated from oracle).

SELECT t1.c1, t2.c2, t3.c3
  from t1, t2, t3
  where t1.flag = 1
        and ( = and = 1)
        and ( ( = and not exists (select * from t3) )
               (t1.c3 = 2)

This looks a bit complex for me as I am not familiar with JOINs. It
would be great if someone can help me out.


Re: converting joins from oracle to mysql wrote:
Quoted text here. Click to load it

The join syntax using "(+)" is specific to Oracle and does not match any
SQL standard.  The equivalent in standard SQL is to use OUTER JOIN.

That join condition makes no sense from what I can tell.  "not exists
(select * from t3)" is true only if the t3 table is empty.  If that is
true, how can any row exist where =  Therefore that term in
the expression is guaranteed to be false, so it can be factored out,
leaving the other side of the "OR" expression.

The best I can guess for this is the following:

SELECT t1.c1, t2.c2, t3.c3
   JOIN t3 ON (t1.c3 = 2)
WHERE t1.flag = 1;

The condition (t1.c3 = 2) is highly unusual and likely not to be what
you intended for this query.  It is more usual for a join condition to
describe a relationship between two tables.

Quoted text here. Click to load it

You should pick up a book or find a tutorial on the web.  JOINs are not
difficult to understand, but they are crucial to writing queries.
Programming in SQL without understanding JOINs is like programming in C
without understanding functions.

Bill K.

Site Timeline