Results 1 to 7 of 7

Thread: [RESOLVED] Ado distinct left join

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2014
    Posts
    52

    Resolved [RESOLVED] Ado distinct left join

    Hello,

    I'm using this SQL statement to left join 2 Excel ranges and it works fine

    Code:
    Sql = "SELECT * FROM " & rs1 & " AS T1 LEFT JOIN  " & rs2 & " AS T2 ON  T1." & CommomVar & "=T2." & CommomVar
    I want the joining to refer to the distinct rows of T2. The statement
    Code:
    Sql = "SELECT * FROM " & rs1 & " AS T1 LEFT JOIN  " & rs2 & " AS DISTINCT T2 ON  T1." & CommomVar & "=T2." & CommomVar
    returns an error

    Any idea?

    Thanks
    Avi

  2. #2
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: Ado distinct left join

    What about something like...

    Code:
    SELECT * FROM range1  AS T1 LEFT JOIN (SELECT DISTINCTROW * FROM range2) AS T2
    ON T1.var = T2.var
    Not tested.

  3. #3
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Ado distinct left join

    You have to put the DISTINCT in the correct location... IN FRONT of the FIELD(s) you want distinct...as part of the SELECT clause.


    Select DISTINCT * from someTable


    http://www.w3schools.com/sql/sql_distinct.asp
    http://technet.microsoft.com/en-us/l.../ms187731.aspx (Example C)
    http://www.techonthenet.com/sql/distinct.php
    http://blog.sqlauthority.com/2007/12...on-discussion/


    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  4. #4

    Thread Starter
    Member
    Join Date
    Apr 2014
    Posts
    52

    Re: Ado distinct left join

    Thanks. It works well!

    Is there any way to count the number of DISTINCT rows. I have tried unsuccessfully

    Code:
    Set rs22 = ObjConnection.Execute("SELECT  COUNT( *)    FROM (SELECT DISTINCT * " & rs2 & " AS T2)")  ' Get nb of rows from recordset
    Avi

  5. #5
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: [RESOLVED] Ado distinct left join

    Moved to the Database Development forum.

  6. #6
    Super Moderator FunkyDexter's Avatar
    Join Date
    Apr 2005
    Location
    An obscure body in the SK system. The inhabitants call it Earth
    Posts
    7,957

    Re: [RESOLVED] Ado distinct left join

    Yes:-
    Select Count (Distinct SomeField)
    From SomeTable
    The best argument against democracy is a five minute conversation with the average voter - Winston Churchill

    Hadoop actually sounds more like the way they greet each other in Yorkshire - Inferrd

  7. #7
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: [RESOLVED] Ado distinct left join

    Not every DBMS accepts predicates in aggregate functions though.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width