views:

834

answers:

5
+2  Q: 

*= in Sybase SQL

I'm maintaining some code that uses a *= operator in a query to a Sybase database and I can't find documentation on it. Does anyone know what *= does? I assume that it is some sort of a join.

select * from a, b where a.id *= b.id

I can't figure out how this is different from:

select * from a, b where a.id = b.id
+3  A: 

It means outer join, a simple = means inner join.

*= is LEFT JOIN and =* is RIGHT JOIN.

(or vice versa, I keep forgetting since I'm not using it any more, and Google isn't helpful when searching for *=)

Lasse V. Karlsen
this answer is right.
Eric Johnson
+4  A: 

From http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.dc34982_1500/html/mig_gde/mig_gde160.htm:

Inner and outer tables

The terms outer table and inner table describe the placement of the tables in an outer join:

  • In a left join, the outer table and inner table are the left and right tables respectively. The outer table and inner table are also referred to as the row-preserving and null-supplying tables, respectively.

  • In a right join, the outer table and inner table are the right and left tables respectively.

For example, in the queries below, T1 is the outer table and T2 is the inner table:

  • T1 left join T2
  • T2 right join T1

Or, using Transact-SQL syntax:

  • T1 *= T2
  • T2 =* T1
Adam Tegen
wow, thanks sybase for making this sound comlicated and confusing.
Eric Johnson
+4  A: 

Of course, you should write it this way:

SELECT *
FROM a
LEFT JOIN b ON b.id=a.id

The a,b syntax is evil.

Joel Coehoorn
I dunno about evil, but it is certainly proprietary to Sybase and Microsoft SQL Server, and not supported by other brands of database.
Bill Karwin
A: 
select * from a, b where a.id = b.id

Requires that a row exist in where b.id = a.id in order to return an answer

select * from a, b where a.id *= b.id

Will fill the columns from b with nulls when there wasn't a row in b where b.id = a.id.

Adam Tegen
+3  A: 

ANSI-82 syntax

select 
    * 
from 
    a
  , b 

where 
     a.id *= b.id

ANSI-92

select 
    * 
from 
   a
  left outer join b 
      on a.id = b.id
jms
I think you mean SQL-89 and SQL-92, not ANSI-82 and ANSI-92.
Bill Karwin