This question already has answers here:
How do I convert a "legacy" left outer join statement in Oracle?
(1 answer)
Assistance replacing oracle (+) joins to ANSI joins
(4 answers)
Oracle LEFT OUTER JOIN on 3+ tables - (+) Syntax versus ANSI Syntax
(3 answers)
Convert old "+" Join to SQL Server syntax?
(2 answers)
Closed 1 year ago.
Lately the (+) has been causing some issues for me, maybe it's depreciated by now.
Now I want to replace the (+) notation with LEFT JOIN, but I can't seem to get the syntax in order.
This is what I have:
SELECT x.a, y.a, z.a
FROM x, y, z
WHERE x.k = y.k(+)
AND x.p = z.p(+);
How can I replace the (+) with a LEFT JOIN?
-EDIT- I've read the "duplicated" answers, and few of them have accepted answers (no wonder why)
I could not solve my problem according to those.
The answer provided here was spot on and solved it - marked it as accepted.
I got another one that is a little bit more confusing (to me)
FROM a,b,c
WHERE b.a = '101'
AND a.a = '202'
AND b.c = a.c
AND a.d = c.d(+)
AND ROWNUM = 1;
Again, I want to replace the (+) with LEFT JOIN
The equivalent syntax would be:
SELECT x.a, y.a, z.a
FROM x LEFT JOIN
y
ON x.k = y.k LEFT JOIN
z
ON x.p = z.p;
Related
I would like to convert this sybase legacy sql code to ansi tsql new standard for ms sql, but I can't find the right way. Any help would be appreciated.
SELECT 3 FROM x_linea_cred, x_linea_cred_priv, x_clt_prd
WHERE x_clt_prd.r_client = #rclient AND
(x_clt_prd.nro_prod *= x_linea_cred.nro_prod or
x_clt_prd.nro_prod *= x_linea_cred_priv.nro_prod))
For a while now, the standard notation for outer join is LEFT [OUTER] JOIN. Your query should be converted to:
select 3
from x_clt_prd c
left join x_linea_cred lc on lc.nro_prod = c.nro_prod
left join x_linea_cred_priv lcp on lcp.nro_prod = c.nro_prod
where c.r_client = #rclient
This question already has answers here:
Oracle outer join syntax
(1 answer)
How do I convert a "legacy" left outer join statement in Oracle?
(1 answer)
Left Outer Join using + sign in Oracle 11g
(3 answers)
Oracle "(+)" Operator
(4 answers)
Closed 5 years ago.
I am working on 2 Tables. One contains 657 rows matching my filter criteria, and the other contains 193 records.
I successfully joined them using Oracle's "AFAIK" syntax:
select
ecp.portfolio_acct, ecp.posn_id cost_posn_id, ecp.asset_id
from MID_COST_POSITION ecp, MID_CASH_POSITION cas
where ecp.portfolio_acct = 10183306
and ecp.portfolio_acct = cas.portfolio_acct(+)
and ecp.asset_id = cas.asset_id(+)
;
However, I cannot seem to replicate these results using ANSI-SQL (or, ISO-sql):
select
ecp.portfolio_acct, ecp.posn_id cost_posn_id, ecp.asset_id
from MID_COST_POSITION ecp
LEFT OUTER JOIN MID_CASH_POSITION cas
on ecp.portfolio_acct = cas.portfolio_acct
where ecp.asset_id = cas.asset_id
and ecp.portfolio_acct = 10183306
;
I have tried various JOINs without success. In the 1st example I had to Outer Join 2 separate fields, which I do not know how to accomplish using ANSI-SQL.
I appreciate any guidance anyone can offer. Thank you!
select
ecp.portfolio_acct, ecp.posn_id cost_posn_id, ecp.asset_id
from MID_COST_POSITION ecp
LEFT OUTER JOIN MID_CASH_POSITION cas
on ecp.portfolio_acct = cas.portfolio_acct
and ecp.asset_id = cas.asset_id
Where ecp.portfolio_acct = 10183306
;
You were turning this into an inner join with the following where condition because it now has to meet that condition in the result set:
ecp.asset_id = cas.asset_id
I'm accustomed to doing this in Oracle (and I think even SqlServer a while back), but I haven't figured out how to do it in sqlite.
A standard "simple" join in sqlite can be done like so:
select *
from kennel k
join kennelbreeder kb
on kb.kennelid = k.rowid;
But if I want to also get some information from the breeder, based on my experience elsewhere, I would expect the following to work, but it doesn't:
select *
from kennel k
join kennelbreeder kb
join breeder b
on kb.breederid = b.rowid
on kb.kennelid = k.rowid;
The error I get is 'Error: near "on": syntax error'. What's the correct way to do this?
In Sqlite, joins may not be nested:
select *
from kennel k
join kennelbreeder kb ON kb.kennelid = k.rowid;
join breeder b on kb.breederid = b.rowid
The on must follow the join. It's just a question about the correct order.
select *
from kennel k
join kennelbreeder kb
on kb.kennelid = k.rowid
join breeder b
on kb.breederid = b.rowid;
Your second example seems to be based on the syntax with nested joins which I've only seen used in MS Access, but it's always with parentheses, which are missing in your example. It would seem that this query works with both MS SQL and SQLite3, and possibly other databases too:
SELECT *
FROM kennel k
JOIN ( kennelbreeder kb
JOIN breeder b
ON kb.breederid = b.rowid )
ON kb.kennelid = k.rowid;
I wouldn't recommend using the latter syntax though as it's unclear and not the standard way of writing joins.
This question already has answers here:
LINQ to SQL Left Outer Join
(6 answers)
left outer join problem
(1 answer)
Closed 9 years ago.
I need to convert this SQL to LINQ, and would really appreciate some help.
SELECT * FROM Adx_eventSet AS es
LEFT JOIN afx_eventsponsor_eventSet AS spon
ON es.Adx_eventId = spon.adx_eventid
Ive tried this but it's not a left join and so only pulled in the one result.
from t in Adx_eventSet
join x in adx_eventsponsor_eventSet on t.Adx_eventId equals x.adx_eventid
select t
You want to use DefaultIfEmpty(). See below.
var leftJoin = from adx_event in Adx_eventSet
join adx_eventsponsor in adx_eventsponsor_eventSet
on adx_event.Adx_eventId equals adx_eventsponsor.adx_eventid into j
from adx_eventsponsor in j.DefaultIfEmpty()
select new
{
Name = adx_event.Name,
Name = adx_eventsponsor != null ? adx_eventsponsor.Name : null
};
Assuming each table has a Name property.
Unfortunately, I don't have access to an Ingres database at the moment and I'm just wondering if the inner join syntax that applies in standard SQL also applies in Ingres?
I'm also wondering about the equivalent to inner join.
For instance, are the following two SQL statements valid?
Statement 1:
SELECT a.Value1,
a.Value2,
b.Value3
FROM Tabletype1 a, Tabletype2 b, Tabletype3 c
WHERE a.Value1 = b.Value4
AND b.Tabletype3_Num = c.Tabletype3_Num
AND p.Value5 = 'Randomvalue'
AND b.Value3 > 20
AND (a.Tabletype1Format = 'Random' OR a.Tabletype1Format = 'Random1')
Statement 2:
SELECT a.Value1,
a.Value2,
b.Value3
FROM Tabletype1 a
INNER JOIN Tabletype2 b
ON a.Value1 = b.Value4
INNER JOIN Tabletype3 c
ON b.Tabletype3_Num = c.Tabletype3_Num
WHERE c.Value5 = 'Randomvalue'
AND b.Value3 > 20
AND (a.Tabletype1Format = 'Random' OR a.Tabletype1Format = 'Random1')
In response to the question the OP actually asked, Ingres absolutely, for sure, definitely does fully support BOTH forms of join specification, and in every case I have ever bothered to look at, it comes up with exactly the same query plan.
So my bottom line answer is do what you think is preferable in your situation. It will work fine.
Both forms work fine in Ingres, although you would appreciate the SQL92 ANSI syntax is more preferable for
readability
clarity
to help the query optimizer know where the join really happens
This question is very similar to SQL Inner Join syntax