Hello, I have a SQL query that links 2 tables. We need to make a restriction on the output, that is, if orders.paid = 1 then we deduce how to implement, here’s the query

$history = mysql_query(" SELECT orders.name, orders.email, orders.paid FROM user INNER JOIN orders ON user.userEmail = orders.email ORDER BY user.userEmail; "); 
  • The output is handled by the client, not the SQL server. - Akina
  • @Akina how can I implement? - Merlin

1 answer 1

  SELECT orders.name, orders.email, orders.paid FROM user, orders WHERE user.userEmail = orders.email and orders.paid = 1 ORDER BY user.userEmail 

It is certainly possible to link the user to the email, but it is better to create an auto-id, well, I don’t like the database of string keys ...

Avoid using a JOIN without a need.