473,466 Members | 1,381 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

not exist in place of outer join

I have this sql statement:

select A.field1,
B.field2
from table1 A,
table2 B
where A.field1=B.field2
If there is no match, I still want to produce a line of output with
field2 showing a blank. Ordinarily I could simply do an outer join.
But because I have more than two tables in my real query, it won't let
me.
So instead, I tried this approach:
select A.field1,
B.field2
from table1 A,
table2 B
where A.field1=B.field2
or not exist
(select 1 from table2 C where C.field2 = A.field1)

But now I get this error:
--------------
Incorrect syntax near the keyword 'select'. Incorrect syntax near ')'.
Statement(s) could not be prepared.
--------------

Any hints as to what I need to fix?

Thanks.
Dennis Hancy
Eaton Corporation
Cleveland, OH

Jul 23 '05 #1
6 1923
It's NOT EXISTS (note the final 'S'). But in any case, you can use
outer joins with any number of tables in the join - if you post a more
complete query, and explain what you mean by "it won't let me" (error,
unexpected results etc.), then someone may be able to help you with it.

Simon

Jul 23 '05 #2
> Ordinarily I could simply do an outer join.
But because I have more than two tables in my real query, it won't let me.


What "won't let you"? Please try to explain your requirements fully:
http://www.aspfaq.com/etiquette.asp?id=5006

The error in your code is due to the typo: EXIST instead of EXISTS

--
David Portas
SQL Server MVP
--

Jul 23 '05 #3
Using MS Query..

If I attempt an outer join, it results in an error message: Cannot have
an outer join if the query has more than two tables.
The existS solution worked great. Thanks.

Any idea how I get around the outer join problem though.

Jul 23 '05 #4
This must be a limitation of the version of Query you are using. There
is no such limitation built into SQL Server. Can you use Query Analyzer
instead and then paste the query to where you need it?

--
David Portas
SQL Server MVP
--

Jul 23 '05 #5
Where do I get Query Analyzer from?

This "not exists" solution is giving me strange results. It is
including all records from table1, as I wanted; however, I would expect
that the field2 value would be blank in those cases where there was no
match in table2. Instead, I am getting values in there (which look
like they are coming from other records).

I am so confused. Can anyone figure out why this is happening?
Dennis

Jul 23 '05 #6
(de*********@eaton.com) writes:
Where do I get Query Analyzer from?


Query Analyser comes with all editions of SQL Server save for MSDE.

If you are using MSDE, you can try OSQL which you can run from a
command-line window. You could put your query in a file, and run
that file with:

osql -E -S server -n -i yourfile.sql

--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 23 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Martin | last post by:
I am now working on SQL Server 2000 having had previous experience on a different database. Both of the OUTER JOIN syntaxes is different from what I am used to and I am finding it slightly...
8
by: Matt | last post by:
Hello I have to tables ar and arb, ar holds articles and a swedish description, arb holds descriptions in other languages. I want to retreive all articles that match a criteria from ar and...
4
by: thilbert | last post by:
All, I have a perplexing problem that I hope someone can help me with. I have the following table struct: Permission ----------------- PermissionId Permission
3
by: Dam | last post by:
Using SqlServer : Query 1 : SELECT def.lID as IdDefinition, TDC_AUneValeur.VALEURDERETOUR as ValeurDeRetour FROM serveur.Data_tblDEFINITIONTABLEDECODES def,...
3
by: Martin | last post by:
Hello everybody, I have the following question. As a join clause on Oracle we use " table1.field1 = table2.field1 (+) " On SQL Server we use " table1.field1 *= table2.field1 " Does DB2...
3
by: deko | last post by:
From what I understand, an Inner Join narrow the rows selected to the table with the least results... and an Outer Join does the opposite... SELECT qryTxToQ1.Q1Total, qryTxToQ2.Q2Total,...
1
by: H5N1 | last post by:
hi there the topic says it all. I have a outer join select statement in tableadapter that populates GridView, I want to make it updatetable, so I need to provide an update command for table...
1
by: Andreas Bauer | last post by:
Hi, when I try a left outer join on one table everything works fine: select * from (tourist.users u left outer join tourist.user_extended_info ue on (u.id = ue.id)) But now I need to do...
5
by: Eitan M | last post by:
Hello, How can I do outer join in ms-access database ? Thanks :)
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.