What does =* mean? - sql

I'm trying to trace some SQL in Microsoft Server. I came across a join that is using a convention unfamiliar to me. What does "=*" mean?
WHERE table1.yr =* table2.yr -1

This:
WHERE t.column =* s.column
...is old TSQL (pre SQL Server 2005) outer join syntax, and is not an ANSI JOIN.
Reference: SQL Server 2005 Outer Join Gotcha

I believe that is old syntax indicating an outer join condition from table1 to table2
Old style:
SELECT * FROM table1, table2
WHERE table1.yr =* table2.yr -1
New style (SQL92):
SELECT * FROM table2
LEFT OUTER JOIN table1 ON table1.yr = table2.yr - 1

This is the old style syntax for expressing joins

It means the code needs to be replaced immediately! This style join is supposed to be a right join. Unfortunately it will sometimes be interpreted as a cross join, so the results of using this join may not be correct. Also, this syntax is deprecated and cannot be used inteh next version of SQl server.

That is the ANSI SQL 1989 syntax for RIGHT OUTER JOIN, where *= would be the LEFT OUTER JOIN.
You should note also that putting the join syntax in the WHERE clause is deprecated in SQL 2008. http://scarydba.wordpress.com/2009/09/15/no-join-predicate/ <== A timely article on this.

This is the old style of joins which were deprecated in ANSI SQL92. New syntax uses INNER and OUTER JOIN which join tables based on expressions rather than equality

A ??? outer join is specified using the symbol =* in place of = in the WHERE clause.

yeap, it's another syntax for a left outer join
from
table1 left outer join table2 on table1.yr = table2.yr - 1

SELECT *
FROM table1, table2
WHERE table1.yr =* table2.yr -1
Means the same thing as this:
SELECT *
FROM
table2
LEFT OUTER JOIN
table1
ON table1.yr = (table2.yr - 1)
The * syntax is considered outdated, and is not in line with the ANSI standards.
Oracle has a similar construct like this:
WHERE table1.yr (+)= table2.yr

To be plain and simple.
This is a SQL-92 outer join operator ( more info )
Don't use it, its very old school, but its similar to LEFT JOIN, and RIGHT JOIN.
All its doing is telling which side of the join is the "Parent" side, so rows on that side will be considered first.
If you try to run this on SQL 2005, it will throw an error, saying that you need to run this in compatibility mode.

There are a lot of silly answers here. You didn't give the FROM clause, so there's no way to tell if your *= represents a LEFT or a RIGHT outer join.
WHERE table1.yr =* table2.yr -1
is old syntax for an outer join, for sure. But anyone who claims to know whether it's a LEFT or RIGHT outer join is mistaken. It depends on the order in which table1 and table2 are named in the FROM clause, and that's not given.

Related

What Does *= means in WHERE Clause in TSQL?

some one have asked me the output of below query.
Select *
from TableA t1, TableB t2
where t1.Id *= t2.Id
Can anyone explain me, if such type of any query exists, if so then how its works. Because i have never seen such type of query Thanks.
UPDATE:
Also when i run this query in SQL Server, i get this;
The query uses non-ANSI outer join operators ("*=" or "=*").
To run this query without modification, please set the compatibility level
for current database to 80, using the SET COMPATIBILITY_LEVEL option
of ALTER DATABASE.
It is strongly recommended to rewrite the query using ANSI outer join
operators (LEFT OUTER JOIN, RIGHT OUTER JOIN).
In the future versions of SQL Server, non-ANSI join operators will
not be supported even in backward-compatibility modes.
Using asterisk in a WHERE is an old non-ANSI compliant syntax for OUTER JOINing tables and therefore should not be used anymore.
Here's the link.
The asterisk in the where condition is actually part of a non-ANSI outer join operator, it is used to define an implicit outer join.
It will cause trouble in modern databases as this operator has been obsolete since 1992.
Essentially the below are the same:
SELECT * FROM TableA LEFT OUTER JOIN TableB ON t1.Id = t2.Id
SELECT * FROM TableA , TableB WHERE t1.Name *= t2.Name
The *= operator means LEFT OUTER JOIN.

(+) symbol in SQL Query

Just i have came across a SQL query in one of the stored procedure like below:
SELECT
*
FROM
account a,
performance p,
customer c,
override o
WHERE
a.account_id = p.account_id (+)
AND a.account_id = c.account_id (+)
AND o.override_type(+) = 'O'
Can you please explain what is the (+) symbol's play here? and the difference of using Left side and right side.
Thanks in advance.
It is the old syntax for OUTER JOIN in Oracle (I don't know whether there are other RDBMS that uses the same old syntax or not).
Better off: Use the explicit ANSI-92 OUTER JOIN syntax using LEFT OUTER JOIN or RIGHT OUTER JOIN instead of the + symbol.
(+) is an legacy outer join syntax in oracle (8 and before). It is very restrictive and handles many cases just wrong. Don't use it anymore. Oracle supports ansi joins (eg. left outer join) since version 9.

extractValue and right outer join - Oracle SQL

i got a little (at least i hope so) problem with an SQL Query. Here's my join
WHERE obj.mod_type = 'SER'
and obj.wrk_id=wrk_lang.id(+)
and extractvalue(value(shm),'/*/#xmi:id','xmlns:xmi="http://www.omg.org/XMI"') = extractvalue(value(shm_con),'/*/#source')(+)
It gives me an "ORA-00936: missing expression"
When i remove the second outer join it works fine(also with a regular join).
Can smb. help me?
It looks to me like this is actually a LEFT outer join - in old-style Oracle syntax the (+) is put on the optional side of the join while in ANSI syntax the required side (LEFT or RIGHT) is called out in the JOIN specification - see this AskTom reference for examples. So, expanding on #FlorinGhita's recommendation to use ANSI JOIN syntax (and making a bit of an assumption about the rest of the statement) we'd get something like
SELECT *
FROM OBJ
LEFT OUTER JOIN WRK_LANG
ON (obj.wrk_id = wrk_lang.id and
extractvalue(value(obj.shm),'/*/#xmi:id','xmlns:xmi="http://www.omg.org/XMI"') =
extractvalue(value(wrk_lang.shm_con),'/*/#source')
WHERE obj.mod_type = 'SER';
Share and enjoy.

What does (+) do in Oracle SQL?

I'm using Oracle SQL Developer to query an Oracle DB (not sure which version it is) and I'm going to use the SQL I make for a Crystal report. Many of the reports the previous developers have written don't use JOIN keywords to make the joins (and I'm not too familiar with JOIN keywords as a result).
Many of the joins they make are made in the WHERE statement. I'll notice something like this.
Select * From TableA, TableB WHERE TableA.PrimaryKey(+) = TableB.ForeignKey
My question is concerning the (+). What purpose does it serve and how do I use it in my code?
It is not recommended. See this previous answer
Difference between Oracle's plus (+) notation and ansi JOIN notation?
That represents a “right outer join” (right because the = is on the right side of the +).
SELECT *
FROM TableA, TableB
WHERE TableA.PrimaryKey(+) = TableB.ForeignKey
is equivalent to
SELECT *
FROM TableA
RIGHT OUTER JOIN TableB
ON (TableA.PrimaryKey = TableB.ForeignKey)
right outer join
(+) is used to perform right outer join in Oracle
RIGHT OUTER JOIN is one of the JOIN operations that allow you to specify a JOIN clause
For details
http://docs.oracle.com/javadb/10.8.3.0/ref/rrefsqlj57522.html

Am I translating Ansi OUTER JOIN syntax correctly to older Sybase (*=) join syntax?

Assuming this is the correct Ansi SQL syntax for a left outer join:
SELECT *
FROM employee LEFT OUTER JOIN department
ON employee.DepartmentID = department.DepartmentID
And this is the correct Ansi SQL syntax for a right outer join:
SELECT *
FROM employee RIGHT OUTER JOIN department
ON employee.DepartmentID = department.DepartmentID
Is this the older Sybase equivalent of a left outer join:
SELECT * FROM employee, department
WHERE employee.DepartmentID *= department.DepartmentID
And this the older Sybase equivalent of a right outer join:
SELECT * FROM employee, department
WHERE employee.DepartmentID =* department.DepartmentID
So we put the * on the left side of the equals sign for a left outer join and on the right side of the equals sign for a right outer join.
Is that correct?
*= is equivalent to a left outer join and ... =* to a right outer join (as you'd have guessed)
You may be interested to note that there is no support for *=* in older releases of Sybase ASE. Semantics and compatibility of Transact-SQL outer joins explains why (PDF)
yes. but sometimes these two may be a little different when handling set of result by where
Yes, that is correct
Why would you be translating from left join to the older syntax, shouldn't you be translating from the older syntax to the preferred newer standard? I don't know about Sybase but since SQl Server is based on Sybase, I suspect it might have the same problem which is that the older syntax does not always correctly get intepreted as an outer join. At times the database might interpret it as a cross join, so in general I don't recommend using it unless you are accessing a database in such an old version that the newer syntax is not available.