Jump to content

Archived

This topic is now archived and is closed to further replies.

saini

help with forming query

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.

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

×

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.