Help with left outer join using three tables

victor64

Well-known member
Joined
Nov 9, 2008
Messages
60
Programming Experience
Beginner
Hello,

I would like to join 3 tables based on a common field. Table 1 should always have data, but data from tables 2 and 3 will not always be available, can you please help me with the left outer join syntax for three tables, below is my code for joining two tables, but the and (after the IN statement) statement is not good because unless there's a link in both tables, table 1 does not show even when available.

mySQL_Statement = "select IDENTIFICATION_DATA.NIIN, IDENTIFICATION_DATA.AIN, USER_REGISTRATION.MC from IDENTIFICATION_DATA, USER_REGISTRATION"

If Not ((TextBox1.Text = String.Empty) And (TextBox2.Text = String.Empty) And (TextBox3.Text = String.Empty) And (TextBox4.Text = String.Empty) And (TextBox5.Text = String.Empty)) Then
mySQL_Statement = mySQL_Statement + " where "
If Not (TextBox1.Text = String.Empty) Then
mySQL_Statement = mySQL_Statement + "IDENTIFICATION_DATA.NSC IN (" + TextBox1.Text & ") and IDENTIFICATION_DATA.NIIN = USER_REGISTRATION.NIIN"
End If

End if

Thanks,

Victor
 
Please post in the most appropriate topic for the topic, not just the first one you come to. The VS forums are for IDE questions, not code questions, and the General forums are for topics that don't fit within other categories. This is a data access question so it obviously belongs in the Data Access forum. Moved.
 
If Table1 is the table that will always have data in it then that's the one that needs to be on the left of a LEFT JOIN, which you haven't included at at:
VB.NET:
SELECT ...
FROM Table1
   LEFT OUTER JOIN Table2
      ON Table1.Table1ID = Table2.Table1ID
   LEFT OUTER JOIN Table3
      ON Table1.Table1ID = Table3.Table1ID
WHERE ...
 
Please post in the most appropriate topic for the topic, not just the first one you come to. The VS forums are for IDE questions, not code questions, and the General forums are for topics that don't fit within other categories. This is a data access question so it obviously belongs in the Data Access forum. Moved.
Actually, it really belongs in the Database area, which I forgot about because I haven't used it for so long, so I've moved it again.
 

Latest posts

Back
Top