jeff5656 Posted October 23, 2009 Share Posted October 23, 2009 I want to select if the doc_type is either s OR f but this doesn't work: $query2 = "SELECT * FROM members WHERE doc_type='s' && doc_type= 'f' ORDER BY username"; Also If I want to do two sorts can I do this: $query2 = "SELECT * FROM members WHERE doc_type='s' && doc_type= 'f' ORDER BY doc_type, username"; Thanks! Link to comment https://forums.phpfreaks.com/topic/178784-query-based-on-2-conditions/ Share on other sites More sharing options...
jcombs_31 Posted October 23, 2009 Share Posted October 23, 2009 You use literals in MYSQL, even so your logic would currently be wrong because you are using AND. SELECT * FROM table WHERE something = 'something' OR 'something_else = 'something_else' Link to comment https://forums.phpfreaks.com/topic/178784-query-based-on-2-conditions/#findComment-943104 Share on other sites More sharing options...
lemmin Posted October 23, 2009 Share Posted October 23, 2009 I know that logical operators work in other databases like Oracle. You are using a logical AND operator. Use OR (or ||): "SELECT * FROM members WHERE doc_type='s' OR doc_type= 'f' ORDER BY username"; Yes, you can sort twice like that. It sorts by the first, then the second, etc. Link to comment https://forums.phpfreaks.com/topic/178784-query-based-on-2-conditions/#findComment-943105 Share on other sites More sharing options...
lmhart Posted October 23, 2009 Share Posted October 23, 2009 Try $query2 = "select * from members where doc_type='s' or doc_type='f' order by username Link to comment https://forums.phpfreaks.com/topic/178784-query-based-on-2-conditions/#findComment-943107 Share on other sites More sharing options...
mrMarcus Posted October 23, 2009 Share Posted October 23, 2009 OR... "SELECT * FROM members WHERE doc_type IN ('s', 'f') ORDER BY username"; Link to comment https://forums.phpfreaks.com/topic/178784-query-based-on-2-conditions/#findComment-943109 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.