0

I have a table which have a column with name domain_name. in domain_name column, different values stores like google.com, facebook.com, twitter.com etc. I try this which is working.

$query= 'Select * from accountdb WHERE domain_name="twitter.com" order by domain_name ASC';

But I want to pick that rows which have the values facebook.com, twitter.com in one query. I try this to achieve but not working.

$query= 'Select * from accountdb WHERE domain_name="twitter.com" and domain_name="facebook.com" order by domain_name ASC';

Alterring quotes

$query= "Select * from accountdb WHERE domain_name='twitter.com' and name='facebook.com' order by domain_name ASC";

Any hint would be appreciated.

9
  • why can't you do select * from accountdb ? Commented Oct 26, 2018 at 15:24
  • either use or or an in clause (select * from accountdb where domain_name in 'twitter.com', 'facebook.com') Commented Oct 26, 2018 at 15:25
  • I can't understand mate, what are you saying? @bhanusengar Commented Oct 26, 2018 at 15:26
  • are you asking me or bhanu sengar? Commented Oct 26, 2018 at 15:26
  • I am saying why didn't you used "select * from accountdb" ? Commented Oct 26, 2018 at 15:27

2 Answers 2

1

And means that both conditions have to be met which will never ever happen. You want domain_name to be either "twitter.com" or "facebook.com". So you have to use or

$query= 'Select * from accountdb WHERE domain_name="twitter.com" or domain_name="facebook.com" order by domain_name ASC';

If you have more than 2 domains to check, best way is to use in.

$query= 'Select * from accountdb WHERE domain_name in ("twitter.com","facebook.com","google.com") order by domain_name ASC';
Sign up to request clarification or add additional context in comments.

4 Comments

If I want to ignore these these three results query may be? $query= 'Select * from accountdb WHERE domain_name!="twitter.com" and domain_name!="facebook.com" and domain_name!="google.com" order by domain_name ASC';
Yes. Or you can use not in. $query= 'Select * from accountdb WHERE domain_name not in ("twitter.com","facebook.com","google.com") order by domain_name ASC';
Select * from accountdb WHERE domain_name NOT IN ("twitter.com","facebook.com") ORDER BY domain_name ASC;
@faisal97 Please mark it as answer if this solves your problem.
0

You can use OR:

$query= 'Select * from accountdb WHERE domain_name="twitter.com" OR domain_name="facebook.com" order by domain_name ASC';

Comments

Your Answer

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