Jump to content

help with forming query


saini

Recommended Posts

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.
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

[!--quoteo(post=380002:date=Jun 4 2006, 11:05 PM:name=fenway)--][div class=\'quotetop\']QUOTE(fenway @ Jun 4 2006, 11:05 PM) [snapback]380002[/snapback][/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.

Link to comment
Share on other sites

[!--quoteo(post=380052:date=Jun 4 2006, 06:38 PM:name=saini)--][div class=\'quotetop\']QUOTE(saini @ Jun 4 2006, 06:38 PM) [snapback]380052[/snapback][/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):

[code]SELECT * FROM yourTable WHERE ( type_tour = 'running' OR type2_tour = 'running' OR type3_tour = 'running' OR type4_tour = 'running' )[/code]

NULLs shouldn't have any effect.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.