dbTalk Databases Forums  

Query question

comp.database.oracle comp.database.oracle


Discuss Query question in the comp.database.oracle forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Perico de los Palotes
 
Posts: n/a

Default Query question - 08-04-2005 , 08:35 AM






I wonder if there is a query for the following:

I have three tables

LOCATION (
LOCATION_NO ) -- there is location 1

EMPLOYEE (
LOCATION_NO,
EMP_NAME ) -- There are two employees for location 1

PRODUCT (
LOCATION_NO,
PRODUCT_NAME ) -- There are three products for location 1

There is no relation between employees and products. Can I get the
following result:


EMP_NAME PRODUCT_NAME

EMP1 PRODUCT1
EMP2 PRODUCT2
PRODUCT3


Thanks in advance for any help.





Reply With Quote
  #2  
Old   
___cliff rayman___
 
Posts: n/a

Default Re: Query question - 08-04-2005 , 11:14 PM






Perico de los Palotes wrote:

Quote:
I wonder if there is a query for the following:

I have three tables

LOCATION (
LOCATION_NO ) -- there is location 1

EMPLOYEE (
LOCATION_NO,
EMP_NAME ) -- There are two employees for location 1

PRODUCT (
LOCATION_NO,
PRODUCT_NAME ) -- There are three products for location 1

There is no relation between employees and products. Can I get the
following result:


EMP_NAME PRODUCT_NAME

EMP1 PRODUCT1
EMP2 PRODUCT2
PRODUCT3





UNTESTED FROM THE TOP OF MY HEAD:

SELECT emp_name, product_name
FROM employee e, product p
WHERE e.location_no = p.location_no
AND e.location in ( SELECT location_no FROM location )

Quote:




--
_____cliff_rayman_________________________________ ____
Business Consulting and Turnaround Management
[web] http://www.rayman.com/
[web] http://all-clear-turnaround-management.com/
[eml] cliff _at_ rayman.com
[phn] 888-736-3802 x701
[fax] 818-743-7404
__________________________________________________ ____


Reply With Quote
  #3  
Old   
Perico de los Palotes
 
Posts: n/a

Default Re: Query question - 08-08-2005 , 02:36 PM



No, that results in the cartesian product of both tables; 6 rows in this
case.

Thanks,

Perico


"___cliff rayman___" <cliff (AT) SPAMMER_GO_HOME_rayman (DOT) com> wrote

Quote:
Perico de los Palotes wrote:

I wonder if there is a query for the following:

I have three tables

LOCATION (
LOCATION_NO ) -- there is location 1

EMPLOYEE (
LOCATION_NO,
EMP_NAME ) -- There are two employees for location 1

PRODUCT (
LOCATION_NO,
PRODUCT_NAME ) -- There are three products for location 1

There is no relation between employees and products. Can I get the
following result:


EMP_NAME PRODUCT_NAME

EMP1 PRODUCT1
EMP2 PRODUCT2
PRODUCT3





UNTESTED FROM THE TOP OF MY HEAD:

SELECT emp_name, product_name
FROM employee e, product p
WHERE e.location_no = p.location_no
AND e.location in ( SELECT location_no FROM location )







--
_____cliff_rayman_________________________________ ____
Business Consulting and Turnaround Management
[web] http://www.rayman.com/
[web] http://all-clear-turnaround-management.com/
[eml] cliff _at_ rayman.com
[phn] 888-736-3802 x701
[fax] 818-743-7404
__________________________________________________ ____




Reply With Quote
  #4  
Old   
___cliff rayman___
 
Posts: n/a

Default Re: Query question - 08-09-2005 , 11:55 PM



Ok - so what does this give you that you dont want?:

SELECT e.emp_name, p.product_name
FROM employee e, product p
WHERE e.location_no = p.location_no

C

Perico de los Palotes wrote:

Quote:
No, that results in the cartesian product of both tables; 6 rows in this
case.

Thanks,

Perico


"___cliff rayman___" <cliff (AT) SPAMMER_GO_HOME_rayman (DOT) com> wrote in message
news:cIBIe.7251$vf.2784 (AT) tornado (DOT) socal.rr.com...


Perico de los Palotes wrote:



I wonder if there is a query for the following:

I have three tables

LOCATION (
LOCATION_NO ) -- there is location 1

EMPLOYEE (
LOCATION_NO,
EMP_NAME ) -- There are two employees for location 1

PRODUCT (
LOCATION_NO,
PRODUCT_NAME ) -- There are three products for location 1

There is no relation between employees and products. Can I get the
following result:


EMP_NAME PRODUCT_NAME

EMP1 PRODUCT1
EMP2 PRODUCT2
PRODUCT3







UNTESTED FROM THE TOP OF MY HEAD:

SELECT emp_name, product_name
FROM employee e, product p
WHERE e.location_no = p.location_no
AND e.location in ( SELECT location_no FROM location )



--
_____cliff_rayman_________________________________ ____
Business Consulting and Turnaround Management
[web] http://www.rayman.com/
[web] http://all-clear-turnaround-management.com/
[eml] cliff _at_ rayman.com
[phn] 888-736-3802 x701
[fax] 818-743-7404
__________________________________________________ ____



Reply With Quote
  #5  
Old   
Perico de los Palotes
 
Posts: n/a

Default Re: Query question - 08-10-2005 , 08:33 AM



Thanks for getting back to me, Cliff

I am trying to get the results in a tabular form, something like

E1 P1
E2 P2
P3

instead of

E1 P1
E1 P2
E1 P3
E2 P1
E2 P2
E2 P3

which is the result from your query. It is just a matter of presentation.

My guess is, I need some combination of subselects, but I cannot figure it
out. An outer join will not do, because there could be either more
products than employees or vice versa.

Regards,



"___cliff rayman___" <cliff (AT) SPAMMER_GO_HOME_rayman (DOT) com> wrote

Quote:
Ok - so what does this give you that you dont want?:

SELECT e.emp_name, p.product_name
FROM employee e, product p
WHERE e.location_no = p.location_no

C

Perico de los Palotes wrote:

No, that results in the cartesian product of both tables; 6 rows in this
case.

Thanks,

Perico


"___cliff rayman___" <cliff (AT) SPAMMER_GO_HOME_rayman (DOT) com> wrote in message
news:cIBIe.7251$vf.2784 (AT) tornado (DOT) socal.rr.com...


Perico de los Palotes wrote:



I wonder if there is a query for the following:

I have three tables

LOCATION (
LOCATION_NO ) -- there is location 1

EMPLOYEE (
LOCATION_NO,
EMP_NAME ) -- There are two employees for location 1

PRODUCT (
LOCATION_NO,
PRODUCT_NAME ) -- There are three products for location 1

There is no relation between employees and products. Can I get the
following result:


EMP_NAME PRODUCT_NAME

EMP1 PRODUCT1
EMP2 PRODUCT2
PRODUCT3







UNTESTED FROM THE TOP OF MY HEAD:

SELECT emp_name, product_name
FROM employee e, product p
WHERE e.location_no = p.location_no
AND e.location in ( SELECT location_no FROM location )



--
_____cliff_rayman_________________________________ ____
Business Consulting and Turnaround Management
[web] http://www.rayman.com/
[web] http://all-clear-turnaround-management.com/
[eml] cliff _at_ rayman.com
[phn] 888-736-3802 x701
[fax] 818-743-7404
__________________________________________________ ____






Reply With Quote
  #6  
Old   
___cliff rayman___
 
Posts: n/a

Default Re: Query question - 08-11-2005 , 01:44 AM



I doubt if you are going to get what you want with a regular query.
Perhaps Discoverer will do what you want.

Perico de los Palotes wrote:

Quote:
Thanks for getting back to me, Cliff

I am trying to get the results in a tabular form, something like

E1 P1
E2 P2
P3

instead of

E1 P1
E1 P2
E1 P3
E2 P1
E2 P2
E2 P3

which is the result from your query. It is just a matter of presentation.

My guess is, I need some combination of subselects, but I cannot figure it
out. An outer join will not do, because there could be either more
products than employees or vice versa.

Regards,



"___cliff rayman___" <cliff (AT) SPAMMER_GO_HOME_rayman (DOT) com> wrote in message
news:jNfKe.7868$vf.93 (AT) tornado (DOT) socal.rr.com...


Ok - so what does this give you that you dont want?:

SELECT e.emp_name, p.product_name
FROM employee e, product p
WHERE e.location_no = p.location_no

C

Perico de los Palotes wrote:



No, that results in the cartesian product of both tables; 6 rows in this
case.

Thanks,

Perico


"___cliff rayman___" <cliff (AT) SPAMMER_GO_HOME_rayman (DOT) com> wrote in message
news:cIBIe.7251$vf.2784 (AT) tornado (DOT) socal.rr.com...




Perico de los Palotes wrote:





I wonder if there is a query for the following:

I have three tables

LOCATION (
LOCATION_NO ) -- there is location 1

EMPLOYEE (
LOCATION_NO,
EMP_NAME ) -- There are two employees for location 1

PRODUCT (
LOCATION_NO,
PRODUCT_NAME ) -- There are three products for location 1

There is no relation between employees and products. Can I get the
following result:


EMP_NAME PRODUCT_NAME

EMP1 PRODUCT1
EMP2 PRODUCT2
PRODUCT3









UNTESTED FROM THE TOP OF MY HEAD:

SELECT emp_name, product_name


FROM employee e, product p


WHERE e.location_no = p.location_no
AND e.location in ( SELECT location_no FROM location )



--
_____cliff_rayman_________________________________ ____
Business Consulting and Turnaround Management
[web] http://www.rayman.com/
[web] http://all-clear-turnaround-management.com/
[eml] cliff _at_ rayman.com
[phn] 888-736-3802 x701
[fax] 818-743-7404
__________________________________________________ ____









--
_____cliff_rayman_________________________________ ____
Business Consulting and Turnaround Management
[web] http://www.rayman.com/
[web] http://all-clear-turnaround-management.com/
[eml] cliff -at-- rayman.com
[phn] 888-736-3802 x701
[fax] 818-743-7404
__________________________________________________ ____


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.