Jump to content

Mysql SELECT multiple values


ayok

Recommended Posts

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 :shrug:)

Link to comment
https://forums.phpfreaks.com/topic/175930-mysql-select-multiple-values/
Share on other sites

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.

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.

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.

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..
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.

Archived

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

×
×
  • 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.