multiple rows =>1 row???

They have: 53 posts

Joined: Oct 2005

Hi all and Merry Christmas!

I wanted to ask how would I deal with the following problem:

Say I have a table [TABLE1]:
customerid name
1 nick
2 george
3 harry

and a [TABLE2]:
number car
1 Lotus
2 BMW
2 FERRARI
2 LADA
3 Lamporgini

If I want to see george's car, I would write: SELECT car from TABLE2 where number ='2';
and I would get :
BWM
FERRARI
LADA

The thing is that I don't want to get 3 lines, but just one, where each record will be separated e.g. by TAB.
But with mysql_fetch_array I will get 3 lines. I must somehow "check" for each person if he has more than one cars,
and show them in one row, not in multiple rows.

I am stuck!

Renegade's picture

He has: 3,022 posts

Joined: Oct 2002

Try this:

SELECT car FROM table2 WHERE number='2' LIMIT='1'
'

chrishirst's picture

He has: 379 posts

Joined: Apr 2005

it's a display problem not a SQL problem if there is three matching rows you will get three returned using LIMIT=1 will only return the first record from the set which maybe BMW or LADA depending on what order you retrieve the records.

get the result, if there is more than one record display accordingly

Chris

Indifference will be the downfall of mankind, but who cares?
Venue Capacity Monitoring
Code Samples

dk01's picture

He has: 516 posts

Joined: Mar 2002

So you are saying instead of seeing:
BWM
FERRARI
LADA

You want to see:
BMW FERRARI LADA

If this is all you want then just take out the in your echo statement and add a space in its place.

Should be fairly simple.

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.