MySQL returns more than one row with AND operator match

by Abu Nooh   Last Updated October 18, 2019 23:06 PM - source

I have two tables 1:n relationship, customer to orders the schema is in the http://sqlfiddle.com/#!9/a6842e/1 I have created.

The key in customer is composite id and type. I am trying to get the email address from the customer table where the order_id is = 2

So the query is:

SELECT email FROM customer c, orders o WHERE o.custId = c.id AND o.id = 2

This is returning two rows even though I specified o.id = 2

Here's a fiddle

How to get just the email where o.id = 2 and that rows foreign key = primary key of customer table.

Any help appreciated.

Tags : join mysql-5.6


Related Questions



JOIN by part of two column names

Updated August 02, 2018 17:06 PM


Inner join on output of a subquery

Updated August 02, 2018 13:06 PM