0

I have the following mysql table:

Products

ID -- NAME -- INSTOCK -- REFERER -- DISCOUNT 
1 -- pen -- 1 -- google.com -- 50 
2 -- mouse -- 0 -- google.ca -- 30
3 -- keyboard -- 1 -- google.ca -- 30
4 -- screen -- 1 -- yahoo.com -- 50
5 -- mother board -- 1 -- yahoo.ca -- 30
6 -- printer -- 1 -- google.com --30

What I'm trying to get is all the rows that have:

INSTOCK equals 1 and the REFERER equals google.com and google.ca

How can I do this?

Thanks a lot

4
  • Just to make sure you want to select products that are in stock and the referrer is either google.com or google.ca? For your example you want 1, 2, 3 and 6 returned? Commented Mar 9, 2011 at 15:30
  • 1
    That seems to be quite impossible. What ID's would you expect to get back from this query? Commented Mar 9, 2011 at 15:33
  • 1
    We probably means google.com or google.ca... Commented Mar 9, 2011 at 15:41
  • The IDs should be 1, 3 and 6. Number 2 has instock= 0. Thanks Commented Mar 9, 2011 at 15:41

3 Answers 3

1

I bet you mean OR, not AND in your question:

Your looking for IN:

SELECT * FROm table WHERE INSTOCK = 1 AND REFERER IN ('google.com', 'google.ca')

Or you could use OR:

SELECT * FROM table WHERE INSTOCK = 1 AND (REFERER = 'google.com' OR REFERER = 'google.ca')
Sign up to request clarification or add additional context in comments.

Comments

0

This is pretty basic SQL:

SELECT ID, NAME
FROM Products
WHERE INSTOCK = 1 AND (REFERER = 'google.com' OR REFERER = 'google.ca');

Further reference:

Comments

0

Use the WHERE statement combined with AND conditions in your query:

// Example
SELECT ID, NAME FROM table WHERE INSTOCK = 1 AND (REFERER = 'google.com' OR REFERER = 'google.ca');

3 Comments

thanks Artusamak but with your query I get 0 results, and that's not true :(
What is your expected result?
@user523129 Read your question again. That's what you asked for ;-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.