Re: sql statement
From: Anders Altberg (x_pragma_at_telia.com)
Date: 06/22/04
- Next message: Anders Altberg: "Re: SELECT result as a table in from list"
- Previous message: miguelitri: "system messages executing ODBC querys"
- In reply to: javier Barrera (jbarrera_at_yahoo.com): "sql statement"
- Next in thread: javier Barrera (jbarrera_at_yahoo.com): "Re: sql statement"
- Reply: javier Barrera (jbarrera_at_yahoo.com): "Re: sql statement"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 22 Jun 2004 14:37:48 +0200
Hello Javier
CREATE cursor Cities (Codcity C(2), namecity C(10))
INSERT INTO Cities VALUES ('01','New York')
INSERT INTO Cities VALUES ('02', 'London')
INSERT INTO Cities VALUES ('03', 'Madrid')
CREATE CURSOR Customers (Custcity C(2), namecustomer C(10))
INSERT INTO Customers Values('01','smith')
INSERT INTO Customers Values ('01', 'brown')
INSERT INTO Customers Values ('02', 'beckham')
INSERT INTO Customers Values ('02', 'Millar')
CREATE CURSOR suppliers (suplcity c(2), namesupplier C(10))
INSERT INTO Suppliers Values ('01', 'John')
INSERT INTO Suppliers Values ('01', 'Peter')
INSERT INTO Suppliers Values ('03','Juan')
INSERT INTO Suppliers Values ('03','Jose')
SELECT C1.namecity,C2.namecustomer,S1.namesupplier ;
FROM Cities C1 ;
LEFT JOIN Customers C2 ON C1.codcity=C2.custcity ;
LEFT JOIN Suppliers S1 ON S1.suplcity=C1.codcity ;
INTO CURSOR Q1
result:
Namecity Namecustomer Namesupplier
New York smith John
New York smith Peter
New York brown John
New York brown Peter
London beckham .NULL.
London Millar .NULL.
Madrid .NULL. Juan
Madrid .NULL. Jose
I don't know why you don't want New York smith Peter and
othere possible ocmbonations.
PS It's always appreciated if you present sample data in runnable code.
-Anders
"javier Barrera (jbarrera@yahoo.com)" <javier Barrera
(jbarrera@yahoo.com)@discussions.microsoft.com> wrote in message
news:4CE89C78-8161-4456-A597-82C2F2D3AD4C@microsoft.com...
> I am trying to write a sql statement but I have had no luck. I have three
tables: city, customers, suppliers, the primary key is codcity
>
> City
> Codcity, namecity
> 01 New York
> 02 London
> 03 Madrid
>
> Customers
> Custcity namecustomer
> 01 smith
> 01 brown
> 02 beckham
> 02 Millar
>
> suppliers
> suplcity namesupplier
> 01 John
> 01 Peter
> 03 Juan
> 03 Jose
>
> I need a result as:
>
> City customer supplier
> New York smith john
> New York brown Peter
> London beckham .null.
> London Millar .null.
> Madrid .null. Juan
> Madrid .null. Jose
>
> Any suggestions?
>
> Thanks in advance,
> Javier.
>
>
>
>
- Next message: Anders Altberg: "Re: SELECT result as a table in from list"
- Previous message: miguelitri: "system messages executing ODBC querys"
- In reply to: javier Barrera (jbarrera_at_yahoo.com): "sql statement"
- Next in thread: javier Barrera (jbarrera_at_yahoo.com): "Re: sql statement"
- Reply: javier Barrera (jbarrera_at_yahoo.com): "Re: sql statement"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|