Re: Please help quick statement check



David (david.goodyear@xxxxxxxxx) writes:
Hi, I was hoping someone could confirm the following about the
following number 2 SQL query:

1. This extracts the data required given that there is a recording to
match the records

2. This should, but im not convinced extract all the remaining records
that do not have a matched recording, but fulfil the rest of the
criteria. If not please help...

These conditions seems to contradict each other.

3. As the two querys produce the same layout of tables if I did a UNION
ALL, this should work shouldnt it?

But why? Why not an outer join instead?

count
(
SELECT rec.*
WHERE rec.whole_phone_number = l.whole_phone_number AND
rec.last_name = l.last_name AND
rec.agent = ai.agent_login AND
rec.campaign = l.campaign
) < 1

An EXISTS clause is what you want. This is odd and less effiecient.


--
Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
.



Relevant Pages

  • Re: VB code for filtering mail merge
    ... SQL statement area. ... The filtering options I selected while recording that macro did produce the ... What actually works depends largely on the data source and partly on the ... Connection string so that when you try to re-execute the recorded macro, ...
    (microsoft.public.word.mailmerge.fields)
  • RE: Using Excel and SQL
    ... it is best that you get it working manually while recording a macro and then ... Then select New SQL ... See if you can get any data from the server using this method. ... post the record macro. ...
    (microsoft.public.excel.misc)
  • Re: INSERT INTO..SELECT
    ... in Excel 2002, not to learn to write SQL or VBA. ... but still the recorded macro is blank. ... >> during the macro recording process, ...
    (microsoft.public.excel.programming)
  • Re: INSERT INTO..SELECT
    ... > SQL INSERT INTO..SELECT statements. ... > during the macro recording process, when I stop recording, ... > the resulting macro is empty. ... macro the recorder and the MS Query wizard write lousy code. ...
    (microsoft.public.excel.programming)
  • Database SQL problem....
    ... I have a script that reads a bunch of files and extracts some data.... ... get a particular result and then use that for a second sql ... push @lines, $_; # push the data line onto the array ... FROM winery ...
    (comp.lang.perl.misc)