Reputation: 533
I'm certain this is a really easy question. I'm new to mysql.
I need to find all emails in a list that i have.
The list is about 40 emails.
[email protected]
[email protected]
[email protected]
[email protected]
I've tried this:
SELECT * FROM `sales_flat_order` WHERE customer_email = "'[email protected]', '[email protected]'"
SELECT * FROM `sales_flat_order` WHERE customer_email = "[email protected], [email protected]"
SELECT * FROM `sales_flat_order` WHERE customer_email in([email protected], [email protected])
and various other queries. any help would be appreciated.
Upvotes: 0
Views: 112
Reputation: 1447
You were close, you want something like this...
SELECT * FROM `sales_flat_order` WHERE customer_email IN('[email protected]', '[email protected]', etc)
you could also do this...
SELECT * FROM `sales_flat_order` WHERE customer_email = '[email protected]' OR customer_email = '[email protected]'
if you only need unique values then you can do this...
SELECT DISTINCT(my_field) FROM `sales_flat_order` WHERE customer_email = '[email protected]' OR customer_email = '[email protected]'
as mentioned in my comment, DISCTINT()
takes a single field as an argument you cannot put *
as the argument.
Upvotes: 1
Reputation: 50
$sql = "SELECT * FROM sales_flat_order ORDER by id ASC";
If you want it to display in descending format, change ASC to DESC
Happy coding!
Upvotes: -1
Reputation: 29
Try
SELECT * FROM sales_flat_order
WHERE customer_email IN('[email protected]', '[email protected]')
Syntax is : SELECT [COLUMN NAME] FROM [TABLE NAME] WHERE [COLUMN] IN ( [VALUE LIST] )
Note: your value list should be in '' if it is a varchar
Upvotes: 1