This topic is locked
[SOLVED]

 SEE TWO O MORE DETAILS TABLES AT THE SAME TIME

2/22/2010 4:08:01 AM
PHPRunner General questions
A
Aleix author

Hi;
We want see two o more details tables at the same time, I mean:
MASTER TABLE CUSTOMER

KAREN

JOHN
DETAILS TABLE INTERES COUNTRY CUSTOMER_____

KAREN - France

KAREN - Italy

JOHN - Portugal
DETAILS TABLE INTERES CITY CUSTOMER_


KAREN - NewYork

JOHN - London

KAREN - Berlin
We like a Select:____
**Customer
Country__City_

KAREN_FRANCE

___
ITALY

NEWYORK

BERLIN
JOHN__PORTUGAL

___LONDON
We want to
see all at the same time
Now, we do: first see the COUNTRYS, AND AFTER DE CITYS, or see all at the same time but with repeat values like:
_
Customer__Country__City_

KAREN_FRANCE___NEYORK

KAREN_FRANCE___BERLIN
This is not nice.
I prefer
_
Customer__Country__City**_

KAREN_FRANCE

___
ITALY

NEWYORK

BERLIN
Some ideas?
Thanks in advance

Sergey Kornilov admin 2/23/2010

Looks a bit artificial but here is an idea you can try.
Do two JOIN queries, then combine then via UNION and sort results by customer name. All depends on what your database supports.



select * from (

select name, country, '' as city from Customer

inner join Countries on Customer.CustomerID=Countries.CustomerID

union

select name, '' as country, city from Customer

inner join Cities on Customer.CustomerID=Cities.CustomerID

) order by 1,2,3
A
Aleix author 2/25/2010

Thanks Sergey;
It is a good idea and it works fine! I use MySql
I do in another way too with this code (MySql)
SELECT
@b:= @a,

(@a:= D1Customer.Customer) AS Customer2,

IF(@b=D1customer.customer, 'same', 'diferent') AS Customer

D1Customer.others AS Others,
FROM Customer AS D1Customer

, Customer AS D2Customer

WHERE D1Customer.IdCustomer = D2Customer.IdCustomer

ORDER BY D1Customer.Customer
Thanks again