saini Posted June 4, 2006 Share Posted June 4, 2006 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,5if query is walking, I get rows 1,4,6and so on.Please help. I went again through mysql documentation, but it seems I am missing something.Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/11175-help-with-forming-query/ Share on other sites More sharing options...
fenway Posted June 4, 2006 Share Posted June 4, 2006 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 Link to comment https://forums.phpfreaks.com/topic/11175-help-with-forming-query/#findComment-41828 Share on other sites More sharing options...
saini Posted June 4, 2006 Author Share Posted June 4, 2006 [!--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. Quote Link to comment https://forums.phpfreaks.com/topic/11175-help-with-forming-query/#findComment-41877 Share on other sites More sharing options...
fenway Posted June 5, 2006 Share Posted June 5, 2006 [!--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. Quote Link to comment https://forums.phpfreaks.com/topic/11175-help-with-forming-query/#findComment-42052 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.