Home > Article > Daily Programming > The difference between in and on in mysql
The difference between MySQL IN and ON: IN is used to compare the value of a column with a list of values, ON is used to join two tables and compare columns with equality or inequality constraints.
In MySQL, IN and ON are both keywords used to specify query conditions, but They have different uses and purposes.
IN
column IN (value1, value2, ..., valueN)
Example:
<code class="sql">SELECT * FROM employees WHERE department IN ('Sales', 'Marketing', 'IT');</code>
This query returns all employee records whose department is "Sales", "Marketing" or "IT".
ON
table1.column = table2.column ON (condition)
##Example:
<code class="sql">SELECT * FROM orders AS o JOIN products AS p ON o.product_id = p.id;</code>This query joins the "orders" and "products" tables and uses the "ON" clause on the "product_id" column for comparison.
Key differences
IN | ON | |
---|---|---|
Compare a column with a list of values | Join two tables and compare columns | |
Filter out records with one of the specific values | Combining data from two tables | |
Not Join table | Join table |
Summary
The above is the detailed content of The difference between in and on in mysql. For more information, please follow other related articles on the PHP Chinese website!