View Single Post

   
  #5 (permalink)  
Old 02-28-2008, 11:29 AM
Rik Wasmus
 
Posts: n/a
Default Re: Problems working with INNER JOIN

On Wed, 31 Oct 2007 09:07:24 +0100, houghi <houghi@houghi.org.invalid>
wrote:

> Rik Wasmus wrote:
>>> SELECT `store_id`
>>> FROM `distance`
>>> WHERE `postcode` =3000
>>> ORDER BY `distance` ASC
>>> LIMIT 0 , 4

>>
>> That's 4, not 5 :P

>
> Yeah, I saw that I had 4 samples, so I changed the code, but not the
> line explaining what I wanted. :-/
>
>>> 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:

>
> You are right. I am sory for not having done that. I should have known
> better.
>
>> 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

>
> That works partialy. OK, it work completely, yet I need something a
> little bit differently. I have stores in "stores" that I do not have in
> "distance" and thus would not like to see.


And it won't. This query checks for store_id's in distance, and joins
stores to it. If a store_id is not in distance, it will never be a result
of this query. If you do get a store you don't want, please post some
sample data and the query used.
--
Rik Wasmus
Reply With Quote