Re: multiple db, multiple table join
| From: | Miguel Cruz | Date: | Fri, 10 May 2002 01:47:43 +0000 |
| Subject: | Re: multiple db, multiple table join | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-96890@lists.php.net to get a copy of this message | ||
This really isn't a PHP question at all. Anyway, you just need to give
nicknames to multiple instances of the same table (here I use e1 and e2).
Something like...
select order_id, e1.last_name, e2.last_name
from tools.orders, hr.emp_master e1, hr.emp_master e2
where orders.emp_id=e1.emp_id
and orders.approved_by=e2.emp_id;
miguel
On Thu, 9 May 2002, Dan Vande More wrote:
> Good evening all,
> I have a strange situation which I cannot think myself out of. To make
> it simple my db looks like this
> (hr db, emp_master table)
> +--------+---------------+
> | emp_id | last_name |
> +--------+---------------+
> | 1 | smith |
> | 3 | wesson |
> | 4 | doe |
> | 6 | clinton |
> | 7 | bush |
> +--------+---------------+
> (tools db, orders table)
> +--------+---------+---------+
> | order_id | emp_id |approved_by |
> +--------+---------+---------+
> | 1 | 1 | 6 |
> | 2 | 4 | 7 |
> | 3 | 3 | 4 |
> | 4 | 7 | 3 |
> | 5 | 6 | 1 |
> +--------+---------+---------+
> I want my query results to be similiar to this:
> if I'm selecting all, this is what I want:
> 1 smith clinton
> 2 doe bush
> 3 wesson doe
> 4 bush wesson
> 5 clinton smith
> It seems so easy, but I've tried hard and cannot get it to work I've
> been going along the lines (changed several times) of
> Select tools.orders.order_id, hr.emp_master.last_name as ordered_by,
> hr.emp_master.last_name as approved_by from tools.orders, hr.emp_master
> where ((tools.orders.emp_id=hr.emp_master.emp_id) and
> (tools.orders.approved_by=hr.emp_master.emp_id))
>
> (I hope I wrote that right, it was freehand, not in db)
> Thank you for any direction you can give me!
> Dam
>
>
>