# Visual Basic > Database Development >  Inner Join

## SteWhit

I have code working fine using Inner Join

Dim adapt As New OleDb.OleDbDataAdapter("Select * From SaleInfo INNER JOIN Leads ON SaleInfo.CallCode = Leads.LeadCode " & DataString & " ORDER BY CDATE(CallDate)", Con)

Now I need to add another Inner Join but I am struggling how to add it to the code, I have tried a few different ways like.....

Dim adapt As New OleDb.OleDbDataAdapter("Select * From SaleInfo (INNER JOIN Leads ON SaleInfo.CallCode = Leads.LeadCode INNER JOIN RestrictedLeads ON SaleInfo.CallCode = RestrictedLeads.RestrictedLeadCode)" & DataString & " ORDER BY CDATE(CallDate)", Con)

Any help appreciated.

----------


## jmcilhinney

This is a SQL question, not a VB question. It belongs in the Database Development forum. I have asked the mods to move it.

You should get rid of the irrelevant VB and just show the SQL code, so the actual problem is easy to see.

----------


## schoemr

hi SteWhit,

I am surprised this was not answered, especially since you did not wrap your code in the correct format. 



```
Dim adapt As New OleDb.OleDbDataAdapter("Select * From SaleInfo (INNER JOIN Leads ON SaleInfo.CallCode = Leads.LeadCode INNER JOIN RestrictedLeads ON SaleInfo.CallCode = RestrictedLeads.RestrictedLeadCode)" & DataString & " ORDER BY CDATE(CallDate)", Con)
```

In the future you select your code and then wrap it like this:



Now regarding you code, the first I see that is wrong is your use of parentheses: (see where I made it red)



```
Dim adapt As New OleDb.OleDbDataAdapter("Select * From SaleInfo (INNER JOIN Leads ON SaleInfo.CallCode = Leads.LeadCode INNER JOIN RestrictedLeads ON SaleInfo.CallCode = RestrictedLeads.RestrictedLeadCode)" & DataString & " ORDER BY CDATE(CallDate)", Con)
```

To join 3 tables there are more than one approach, some guys here are extremely knowledgeable and I am sure they can show you. But this is a simple example:



```
SELECT orders.order_id, orders.order_date, customers.name, products.product_name
FROM orders
INNER JOIN customers
ON orders.customer_id = customers.customer_id
INNER JOIN products
ON orders.product_id = products.product_id;
```

Now, with your query. I did not test it, but I think it should be something like:



```
Dim adapt As New OleDb.OleDbDataAdapter("Select * From SaleInfo INNER JOIN Leads ON SaleInfo.CallCode = Leads.LeadCode INNER JOIN RestrictedLeads ON SaleInfo.CallCode = RestrictedLeads.RestrictedLeadCode " & DataString & " ORDER BY DATE(CallDate)", Con)
```

Also, 

```
CDATE(CallDate)
```

 - was this working? I'm not saying it won't I just seems old perhaps. In this code I changed it to 

```
DATE
```

I googled CDATE and yes it is used in VBA and also MS Access....

----------


## jmcilhinney

> In the furutre you can wrap your code like this:
> 
> Attachment 186639


Your attachment is invalid. The Insert Image function on the main editor toolbar doesn't work. You need to click Go Advanced and then Manage Attachments to successfully attach an image.

----------


## schoemr

> Your attachment is invalid. The Insert Image function on the main editor toolbar doesn't work. You need to click Go Advanced and then Manage Attachments to successfully attach an image.



Thanks

----------

