Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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