Re: SQL question ?
From: Murali.L (muralil_at_olamtanzania.com)
Date: 07/02/04
- Next message: J French: "Re: Pausing Execution of VB Code"
- Previous message: sxm: "New question"
- In reply to: Jeff Johnson [MVP: VB]: "Re: SQL question ?"
- Next in thread: Phil Hunt: "Re: SQL question ?"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 2 Jul 2004 10:15:48 +0300
Thanks Jeff really good examples...
Murali.
"Jeff Johnson [MVP: VB]" <i.get@enough.spam> wrote in message
news:OJa4P83XEHA.3536@TK2MSFTNGP11.phx.gbl...
>
> "Murali.L" <muralil@olamtanzania.com> wrote in message
> news:O1eUPa3XEHA.2844@TK2MSFTNGP12.phx.gbl...
>
> > I wrote SQL with join but it gives me an error... so I removed the SQL,
I
> > dont have now. But i wanted to know how to writer the
> > SQL with Join. If u can give me the syntax, that will help me.
>
> SELECT <columns>
> FROM <table1> <alias1> INNER JOIN <table2> <alias2>
> ON <alias1>.<column> = <alias2>.<column>
> [INNER JOIN <table3> <alias3> ON <alias3>.<column> = <alias1 or
> 2>.<column>]
> [...and so on]
>
> Example (2 tables):
>
> SELECT c.CustomerName, o.OrderNumber, o.OrderDate
> FROM Customers c INNER JOIN Orders o ON c.CustomerID = o.CustomerID
>
> Example (3 tables):
>
> SELECT c.CustomerName, o.OrderNumber, o.OrderDate, s.ShipperName
> FROM Customers c INNER JOIN Orders o ON c.CustomerID = o.CustomerID
> INNER JOIN Shippers s ON o.ShipperID = s.ShipperID
>
> Example (4 tables--notice that one table serves only to link two others):
>
> SELECT c.CustomerName, o.OrderNumber, o.OrderDate, p.PartName
> FROM Customers c INNER JOIN Orders o ON c.CustomerID = o.CustomerID
> INNER JOIN OrderItems oi ON oi.OrderID = o.OrderID
> INNER JOIN Parts p ON p.PartID = oi.PartID
>
>
> Aliases are not required but I personally think writing out table names in
> front of each column makes the SQL way too wordy. Others will disagree.
>
> Also, the order of the columns in the ON clause is not significant when
> using = (which you will use 99.999999999999999999999999% of the time). You
> can use
>
> ON c.CustomerID = o.CustomerID
>
> or
>
> ON o.CustomerID = c.CustomerID
>
>
- Next message: J French: "Re: Pausing Execution of VB Code"
- Previous message: sxm: "New question"
- In reply to: Jeff Johnson [MVP: VB]: "Re: SQL question ?"
- Next in thread: Phil Hunt: "Re: SQL question ?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|