473,785 Members | 2,553 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

The EXISTS operator in A97 SQL - I cannot find documentation on it in A97 HELP

MLH
Mr Leigh Purvis gave me a very clever piece of SQL to accomplish what
is probably an uncommon objective. In it, he uses the EXISTS operator.
I can find no documentation on it in A97 HELP. I would like to read
more about this useful SQL operator. Suggestions?

SELECT CustID, OutType, EXISTS (SELECT CustID FROM tblCorresponden ce
AS tblC
WHERE tblC.CustID = tblCorresponden ce.CustID AND tblC.OutType = "01")
AS
LogicalField FROM tblCorresponden ce WHERE tblCorresponden ce.OutType
=
"05"

Nov 13 '05 #1
15 1915
MLH wrote:
Mr Leigh Purvis gave me a very clever piece of SQL to accomplish what
is probably an uncommon objective. In it, he uses the EXISTS operator.
I can find no documentation on it in A97 HELP. I would like to read
more about this useful SQL operator. Suggestions?

SELECT CustID, OutType, EXISTS (SELECT CustID FROM tblCorresponden ce
AS tblC
WHERE tblC.CustID = tblCorresponden ce.CustID AND tblC.OutType = "01")
AS
LogicalField FROM tblCorresponden ce WHERE tblCorresponden ce.OutType
=
"05"


http://msdn.microsoft.com/library/de...lce_exists.asp

SQL Server does a great job of optimising this, IME Access does not, I
see most people use exists(select * from...), which looks resource
hungry but SQL Server doesn't actually select all columns in this
instance. Not sure what Access does though.

You'll have to test for yourself but you might find using DCount() (or
my tCount()) to be more efficient against Access tables, YMMV.

Nov 13 '05 #2
What is the "uncommon objective"?

Nov 13 '05 #3
Execution Plans: Which is more efficient?

--- Query15 ---

**** (inserted by poster) ****
SELECT *
FROM Table1
WHERE EXISTS(SELECT NUMBER FROM Table2 WHERE Table1.ID=Table 2.Number);
**** (end insert) ****

- Inputs to Query -
Table 'Table2'
Table 'Table1'
- End inputs to Query -

01) Sort table 'Table2'
02) Semi Join table 'Table1' to result of '01)'
using temporary index
join expression "Table1.ID=Tabl e2.Number"

--- Query16 ---

**** (inserted by poster) ****
SELECT *
FROM Table1 INNER JOIN Table2 ON Table1.ID = Table2.Number;
**** (end insert) ****

- Inputs to Query -
Table 'Table1'
Using index 'ID'
Having Indexes:
ID 10 entries, 1 page, 10 values
which has 1 column, fixed, clustered and/or counter
Table 'Table2'
- End inputs to Query -

01) Inner Join table 'Table2' to table 'Table1'
using index 'Table1!ID'
join expression "Table2.Number= Table1.ID"

----
I never use EXISTS, preferring JOINS.

Nov 13 '05 #4
MLH
Well, I was probably wrong in saying that. I thought it more
common for a query to extract say 3 rows from a 10 row table
displaying data from ONLY the 3 of the 10 records than to
extract the same 3 rows, but mention (with an extra field)
data from say another 4th and 5th row of the table being
examined.

What is the "uncommon objective"?


Nov 13 '05 #5
Bri

MLH wrote:
Mr Leigh Purvis gave me a very clever piece of SQL to accomplish what
is probably an uncommon objective. In it, he uses the EXISTS operator.
I can find no documentation on it in A97 HELP. I would like to read
more about this useful SQL operator. Suggestions?


It is in the help for 'Subqueries - SQL Subqueries' in the Index or look
for EXISTS in Find to get to the same place.

--
Bri

Nov 13 '05 #6
MLH
FOUND IT! Thank-you very much, Bri.

It is in the help for 'Subqueries - SQL Subqueries' in the Index or look
for EXISTS in Find to get to the same place.

A subquery is a SELECT statement nested inside a SELECT,
SELECT...INTO, INSERT...INTO, DELETE, or UPDATE statement or inside
another subquery.

Syntax

You can use three forms of syntax to create a subquery:

comparison [ANY | ALL | SOME] (sqlstatement)
expression [NOT] IN (sqlstatement)
[NOT] EXISTS (sqlstatement)

A subquery has these parts:

Part Description
comparison An expression and a comparison operator that compares
the expression with the results of the subquery.
expression An expression for which the result set of the subquery
is searched.
sqlstatement A SELECT statement, following the same format and
rules as any other SELECT statement. It must be enclosed in
parentheses.
Nov 13 '05 #7
"lylefair" <ly******@yahoo .ca> wrote in
news:11******** *************@g 44g2000cwa.goog legroups.com:
Execution Plans: Which is more efficient?

--- Query15 ---

**** (inserted by poster) ****
SELECT *
FROM Table1
WHERE EXISTS(SELECT NUMBER FROM Table2 WHERE
Table1.ID=Table 2.Number); **** (end insert) ****

- Inputs to Query -
Table 'Table2'
Table 'Table1'
- End inputs to Query -

01) Sort table 'Table2'
02) Semi Join table 'Table1' to result of '01)'
using temporary index
join expression "Table1.ID=Tabl e2.Number"

--- Query16 ---

**** (inserted by poster) ****
SELECT *
FROM Table1 INNER JOIN Table2 ON Table1.ID = Table2.Number;
**** (end insert) ****

- Inputs to Query -
Table 'Table1'
Using index 'ID'
Having Indexes:
ID 10 entries, 1 page, 10 values
which has 1 column, fixed, clustered and/or counter
Table 'Table2'
- End inputs to Query -

01) Inner Join table 'Table2' to table 'Table1'
using index 'Table1!ID'
join expression "Table2.Number= Table1.ID"

----
I never use EXISTS, preferring JOINS.

Query16, which uses the join, will return as many rows as there
are in table 2. Repeat your plan with SELECT DISTINCT and you
may not find it as speedy.
--
Bob Quintal

PA is y I've altered my email address.
Nov 13 '05 #8
No.
Query16 returns only one row with all the fields from both Table1 and
Table2. This row has both Table1.ID and Table2.Number = 9. This is the
only match that exists.

Query15 also returns one row, but only the fields of Table1 are
included.

Nov 13 '05 #9
Reading the rest of your post: of course,this is not MY plan. It is
JET's compilation plan and manifests itself in showplan.out after
inserting this key in the registry:

[HKEY_LOCAL_MACH INE\SOFTWARE\Mi crosoft\Jet\4.0 \Engines\Debug]
"JETSHOWPLAN"=" ON"

And as speedy as what? I didn't say it was speedy and I don't know if
it's speedy. We were discussing whether or not JET optimizes The EXISTS
operator.
After looking at the compilation plan my guess is ... probably not.

Nov 13 '05 #10

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

Similar topics

2
13851
by: Newbie | last post by:
Hi, Could someone please tell how MINUS operator works for comparing and giving non-matching records in Table1? Does MINUS operator compares all records of Table1 with all records of Table2 to give differences? Say, i've got 2 tables - no keys defined on them. No PK and UK. Now MINUS operator will pick which columns for comparison? Having a PK/UK, i see it as comparing these keys and susequently the rest of fields for matcing key records,...
16
2620
by: Edward Diener | last post by:
Is there a way to override the default processing of the assignment operator for one's own __value types ? I realize I can program my own Assign method, and provide that for end-users of my class, but I would like to use internally my own = operator for some of my value types, so I can say "x = y;" rather than "x.Assign(y);". The op_Assign operator seems impossibly broken since it takes __value copies of the two objects. Perhaps there is...
34
6472
by: Pmb | last post by:
I've been working on creating a Complex class for my own learning purpose (learn through doing etc.). I'm once again puzzled about something. I can't figure out how to overload the assignment operator. Here's what I'm trying to do. I've defined class Complex as class Complex { friend ostream &operator<<( ostream &, Complex & ); public: Complex( float = 0.0, float = 0.0 );
8
5483
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- Hello, I have a very simple problem but cannot seem to figure it out. I have a very simple php script that sends a test email to myself. When I debug it in PHP designer, it works with no problems, I get the test email. If
2
2372
by: Javier Estrada | last post by:
1. For types smaller than int, when I compile: class MyClass { static void Main(string args) { x = 10; y = -x; }
6
13731
by: Chad Crowder | last post by:
Getting the following error on my production server whether the file exists or not: "System.IO.IOException: Cannot create a file when that file already exists." Here's the code generating the error (seems to be happening when I try creating a directory) If dirmgr.Exists("s:\blah\" & txt_name.Text) Then lblerror.Text = lblerror.Text & "Unable to build physical path. " &
10
22776
by: Geoff Jones | last post by:
Hi I'm trying to drop a table by using: Dim cmd As New OleDbCommand("DROP TABLE IF EXISTS books", myconnection) cmd.ExecuteNonQuery() but I get a syntax error: "Syntax error in DROP TABLE or DROP INDEX"
19
2236
by: scroopy | last post by:
Is it impossible in C++ to create an assignment operator for classes with const data? I want to do something like this class MyClass { const int m_iValue; public: MyClass(int iVal):m_iValue(iVal){}
22
3625
by: clicwar | last post by:
A simple program with operator overloading and copy constructor: #include <iostream> #include <string> using namespace std; class Vector { private: float x,y; public: Vector(float u, float v);
0
9645
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10324
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10147
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10090
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
5380
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4050
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 we have to send another system
2
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.