View Single Post

   
  #4 (permalink)  
Old 02-28-2008, 10:29 AM
houghi
 
Posts: n/a
Default Re: Problems working with INNER JOIN

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. I asume I could add an extra
field in "stores" to wether to show it or not and that would be my
prefered choice.

Will look into that. Mainly I need to add the following information
anyway: Is the store open or closed. Is the store for b2b or b2c? I do
not want b2b customers going to a b2c store.

The above already helped me a lot. Thanks.

Just another question for people with experience: would it be wiser to
have the names store_id and StoreNumber or would it be better to use the
same name for both? I can see advantages and disadvatages in both, yet
would like to hear wath people working with databases and MySQL think
about that.

houghi
--
houghi http://houghi.org http://www.plainfaqs.org/linux/
http://www.netmeister.org/news/learn2quote.html
>
> Today I went outside. My pupils have never been tinier...

Reply With Quote