SBendBuckeye
Programmer
Hello,
If someone could help me figure out the correct Oracle SQL syntax, I would be greatly appreciative. I have to query an Oracle database for Customer information. It will be read only and there are around 5600 total customers. This is the only Oracle piece in the whole project which is already behind schedule so I don't dare take much time.
What I need to do is populate a form combobox with a list of customers, some of which have multiple locations and client ids. Here is the simple case:
If a customer has multiple locations I need to append the city and state so the user can differentiate them.
Customer1
Customer2
Customer3 City1 State1
Customer3 City2 State1
Customer3 City3 State2
Customer4
Here is how I plan to do it:
Here are the problems I am having:
1. According to some documentation I read, SubQueries in Oracle are very slow and the MINUS statement should be used in its place. Here is what I would do in SQL Server and what I think I need to do in Oracle for the top half of a Union query (those with only 1 record):
For the bottom half (eg those with multiple records), I need to add the address table which requires a left join. Again, here are both examples so you can see what I am trying to do:
Putting everything together, I think this is what I need:
Now here's the kicker, there can be multiple address records for a single customer record. This means the bottom half of my query will return too many records.
What I need it to do is only return 1 so I can concatenate the city and state with the customer name. I think I was close up to this point and now I'm stuck. Thanks for any ideas and/or suggestions!
Have a great day!
j2consulting@yahoo.com
If someone could help me figure out the correct Oracle SQL syntax, I would be greatly appreciative. I have to query an Oracle database for Customer information. It will be read only and there are around 5600 total customers. This is the only Oracle piece in the whole project which is already behind schedule so I don't dare take much time.
What I need to do is populate a form combobox with a list of customers, some of which have multiple locations and client ids. Here is the simple case:
Code:
Select CustID, CustName From Customer
Customer1
Customer2
Customer3 City1 State1
Customer3 City2 State1
Customer3 City3 State2
Customer4
Here is how I plan to do it:
Code:
CustomerName || ' - ' || City || ' - ' || State
Here are the problems I am having:
1. According to some documentation I read, SubQueries in Oracle are very slow and the MINUS statement should be used in its place. Here is what I would do in SQL Server and what I think I need to do in Oracle for the top half of a Union query (those with only 1 record):
Code:
Select CustID, CustName From Customer Where CustName Not In
(Select CustName From Customer Group By CustName Having Count(CustName) > 1)
Select CustID, CustName From Customer
Minus
Select CustName From Customer Group By CustName Having Count(CustName) > 1)
Code:
Select c.CustID, c.CustName & ' - ' & c.City
From Customer c Left Join Addr a On c.CustID = a.CustID
Where CustName In
(Select CustName From Customer Group By CustName Having Count(CustName) > 1)
Select c.CustID, c.CustName || ' - ' || c.City
From Customer c, Addr a
Where c.CustID = a.CustID(+)
Minus
Select c.CustID, c.CustName || ' - ' || c.City
From Customer c, Addr a
Where c.CustID = a.CustID(+)
Group By CustName Having Count(CustName) > 1)
Code:
Select CustID, CustName From Customer
Minus
Select CustName From Customer Group By CustName Having Count(CustName) > 1)
Union
Select c.CustID, c.CustName || ' - ' || c.City
From Customer c, Addr a
Where c.CustID = a.CustID(+)
Minus
Select c.CustID, c.CustName || ' - ' || c.City
From Customer c, Addr a
Where c.CustID = a.CustID(+)
Group By CustName Having Count(CustName) > 1)
What I need it to do is only return 1 so I can concatenate the city and state with the customer name. I think I was close up to this point and now I'm stuck. Thanks for any ideas and/or suggestions!
Have a great day!
j2consulting@yahoo.com