0

Could you explain me please how to performe the left join in my code ADODB. Actually, I have a inner join in my code, I don't know how to modify the syntax :

Public Sub SUPP_D_ATTENTE(NO_POLICE As String)
Dim RECSET As New ADODB.Recordset
RECSET.Open "select  sousc.lp_etat_doss as cd_rga from db_dossier sousc, db_personne pers, db_garantie gar, db_ctrat_support ctrats, db_param_mandat_op mandaop, db_rga rga" & _
            " where sousc.no_police = '" & NO_POLICE & "' and sousc.cd_dossier = 'SOUSC' and sousc.lp_etat_doss not in ('ANNUL','A30','IMPAY') 

Thank you for your help

2 Answers 2

1

The JOIN comes after the SELECT and before the WHERE

 " SELECT sousc.lp_etat_doss as cd_rga" & _
 " FROM db_dossier sousc" & _
 
 " LEFT JOIN db_garantie gar" & _
 "   ON gar.is_protocole = sousc.is_protocole" & _
   
 " WHERE sousc.no_police = '" & NO_POLICE & "'" & _
 "   AND sousc.cd_dossier = 'SOUSC'" & _
 "   AND sousc.lp_etat_doss NOT IN ('ANNUL','A30','IMPAY')" & _ 
 "   AND gar.cd_garantie  = 'DEDIE'"
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for your answer. The « where » statement cames always at the end ? I mean that firstly, before the joining, I need to filter the data db_dossier.
@Marie The WHERE filters the data. LEFT JOIN returns all records - see w3schools.com/sql/sql_join.asp. I suspect what you need is a subquery - see learn.microsoft.com/en-us/sql/relational-databases/performance/…
0

Assuming you have 3 tables, you need to create a subquery. If you have 4 tables, you will have to create one more subquery.

tableA, tableB, tableC

select c.field1, c.field2, d.field1, d.field2 from
    ( select a.field1 as field1, b.field2 as field2 from
        ( select * from tableA where field1 = 'aaa' and field2 ='123') as a left join tableB as b
        on a.field1= b.field1
     ) as c
left join tableC as d 
on c.field2 = d.field2

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.