ayok Posted September 29, 2009 Share Posted September 29, 2009 I think it's a simple problem, but I cannot solve it. I need to select from a table where a column has 2 value. For example I have table 'mytable' and a column 'year'. I need to select all where the year is 2007 and 2008. How should I make a query? I've tried SELECT * FROM mytable WHERE year = '2007' AND year = '2009', but it seems that it doesn't work this way. Could someone please help me? (what's wrong with the enter button? I cannot make a paragraf/break line ) Quote Link to comment https://forums.phpfreaks.com/topic/175930-mysql-select-multiple-values/ Share on other sites More sharing options...
Maq Posted September 29, 2009 Share Posted September 29, 2009 I need to select all where the year is 2007 and 2008. First of all in your query you use 2009 not 2008. Second, I think you want an OR, I don't think cars can have 2 years. If that doesn't help, then I suggest posting your structure, example data, and desired results. Quote Link to comment https://forums.phpfreaks.com/topic/175930-mysql-select-multiple-values/#findComment-927023 Share on other sites More sharing options...
ayok Posted September 29, 2009 Author Share Posted September 29, 2009 Err.. thank's Maq, for a really fast answer and reaction. I meant 2009. Another example. I have a list of people who are in separate groups, say group A, B, C, and D. I need to send email to people who are in group A and B. So the query I have is like SELECT email FROM table WHERE group = A AND group = B. But it doesn't work. Quote Link to comment https://forums.phpfreaks.com/topic/175930-mysql-select-multiple-values/#findComment-927026 Share on other sites More sharing options...
Maq Posted September 29, 2009 Share Posted September 29, 2009 When you say: I need to send email to people who are in group A and B do you mean, A or B or people that are in A and B (1 person in both groups)? If it's the first scenario then you should apply the same concept, change AND to OR. Quote Link to comment https://forums.phpfreaks.com/topic/175930-mysql-select-multiple-values/#findComment-927032 Share on other sites More sharing options...
ayok Posted September 29, 2009 Author Share Posted September 29, 2009 When you say: I need to send email to people who are in group A and B do you mean, A or B or people that are in A and B (1 person in both groups)? If it's the first scenario then you should apply the same concept, change AND to OR. I need to send to all the people who are in group A and B (not 1 person, and not group C and D). Every person only has one group. Should I change AND to OR? This AND OR confuses me.. Quote Link to comment https://forums.phpfreaks.com/topic/175930-mysql-select-multiple-values/#findComment-927040 Share on other sites More sharing options...
Maq Posted September 29, 2009 Share Posted September 29, 2009 Every person only has one group. Key phrase. If everyone person can only be in a single group then using AND wouldn't return anything, because that implies that a person could be in A and B at the same time. The short answer is yes, change your clause to OR. Quote Link to comment https://forums.phpfreaks.com/topic/175930-mysql-select-multiple-values/#findComment-927042 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.