MySQL NOT

The NOT operator is used to negate a condition in a SQL query. It returns records where the specified condition is not true.

Example with Tamil Kings

1. Using NOT to Negate a Condition

SELECT * FROM tamil_kings_auto_increment
WHERE NOT reign_period = '985–1014 CE';

Code Explanation: This query selects records from the tamil_kings_auto_increment table where the reign_period is not '985–1014 CE'.

Best Practices

  • Use NOT to exclude specific data from the results.
  • Be careful when combining NOT with other logical operators to ensure correct filtering logic.

Key Takeaways

  • The NOT operator negates a condition, returning records where the condition is false.
  • It is useful for excluding specific records from a query result.