Jump to content


Photo

help with forming query


  • Please log in to reply
3 replies to this topic

#1 saini

saini
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 04 June 2006 - 05:48 PM

I have a table with 4 fields.
-------------------------tour------------------------------------
type_tour | type2_tour |type3_tour | type4_tour
------------------------------------------------------------------
running | climbing | walking | fishing
--------------------------------------------------------------------
running | fishing | NULL | NULL
--------------------------------------------------------------------
climbing | running | fishing | NULL
---------------------------------------------------------------------
walking | fishing | running | NULL
---------------------------------------------------------------------
fishing | running | NULL | NULL
----------------------------------------------------------------------
walking | NULL | NULL | NULL
--------------------------------------------------------------------

Is it possible to query mysql such as:
show all rows where type_tour or type2_tour or type3-tour or type4_tour is equal to entered value (entered value can be any one)
So, if query is running, I get rows 1,2,3,4,5
if query is walking, I get rows 1,4,6
and so on.

Please help. I went again through mysql documentation, but it seems I am missing something.
Thanks.
Thanks,
saini
! There's always something that we don't even know, that we don't know!
[a href="http://www.gigadesignonline.ru" target="_blank"]создание сайта[/a]

#2 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 04 June 2006 - 07:05 PM

While it is possible to accomplish this with a great deal of OR conditions, the better way would be to have another table where you can associate each tour with multiple type. This would make the querying very simple.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#3 saini

saini
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 04 June 2006 - 10:38 PM

[!--quoteo(post=380002:date=Jun 4 2006, 11:05 PM:name=fenway)--][div class=\'quotetop\']QUOTE(fenway @ Jun 4 2006, 11:05 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
While it is possible to accomplish this with a great deal of OR conditions, the better way would be to have another table where you can associate each tour with multiple type. This would make the querying very simple.
[/quote]

I would love too, but already everything is complcated. Can't use another table for tour types.
Any ideas how to do it with OR's?
Trying for 3 days here but can't get it right. The problem is some fields are NULL, so results go vary.


Thanks,
saini
! There's always something that we don't even know, that we don't know!
[a href="http://www.gigadesignonline.ru" target="_blank"]создание сайта[/a]

#4 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 05 June 2006 - 03:35 PM

[!--quoteo(post=380052:date=Jun 4 2006, 06:38 PM:name=saini)--][div class=\'quotetop\']QUOTE(saini @ Jun 4 2006, 06:38 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
I would love too, but already everything is complcated. Can't use another table for tour types.
Any ideas how to do it with OR's?
Trying for 3 days here but can't get it right. The problem is some fields are NULL, so results go vary.
[/quote]
Well, if you're stuck with the current design, then you'll have to hack it (UNTESTED):

SELECT * FROM yourTable WHERE ( type_tour = 'running' OR type2_tour = 'running' OR type3_tour = 'running' OR type4_tour = 'running' )

NULLs shouldn't have any effect.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users