Re: Problems working with INNER JOIN On Tue, 30 Oct 2007 22:10:24 +0100, houghi <houghi@houghi.org.invalid>
wrote:
> I have a query that gies me the distice from a postalcode to a store. It
> gives me the five closest stores:
>
> SELECT `store_id`
> FROM `distance`
> WHERE `postcode` =3000
> ORDER BY `distance` ASC
> LIMIT 0 , 4
That's 4, not 5 :P
> Output is here
> 1080
> 1008
> 1121
> 1073
>
> I also have a query that will give me the data from the store:
> SELECT `StoreNumber` , `StoreName` , `Address` , `ZipCode` , `City` ,
> `StorePhone`
> FROM `stores`
> WHERE `StoreNumber` =1080
> LIMIT 0 , 30
>
> Now obviously I would like to have a query that wll give me an outpit
> like:
> 1080 Store_X Street_X 3000 Leuven 016/123456
> 1008 Store_B Street_B 3200 Aarschot
> 1121 Store_Z Street_Z 2000 Antwerpen 03/1234567
> 1073 Store_A Street_A 9000 Gent 09/1234567
>
> How can I achieve this? I have looked, yet when I try I get an error
> that there is more then one line.
Giving the query you tried would have helped. Try something like:
SELECT d.`store_id`, s.*
FROM `distance` d
JOIN `stores` s
ON s.StoreNumber = d.store_id
WHERE `postcode` =3000
ORDER BY d.`distance` ASC
LIMIT 0, 4
--
Rik Wasmus |