Golang Tutorials - Learn Go Programming with Easy Step-by-Step Guides

Explore comprehensive Golang tutorials for beginners and advanced programmers. Learn Go programming with easy-to-follow, step-by-step guides, examples, and practical tips to master Go language quickly.

And in SQL

And in SQL

? AND Operator in SQL

The AND operator in SQL is used to combine multiple conditions in a WHERE, HAVING, or ON clause. It returns TRUE only if all conditions are true.


? Syntax

SELECT column1, column2FROM table_nameWHERE condition1 AND condition2;

? Example Table: employees

idnamedepartmentsalary
1AliceHR50000
2BobIT60000
3CarolHR45000

? Example 1: AND in WHERE clause

SELECT name, salaryFROM employeesWHERE department = 'HR' AND salary > 46000;

Output:

namesalary
Alice50000

? Only rows where both conditions are true are selected.


? Example 2: AND with OR

SELECT nameFROM employeesWHERE department = 'IT' OR (department = 'HR' AND salary > 46000);
  • Use parentheses () to control logic and precedence.


? Key Points

  • AND has higher precedence than OR.

  • Use () to group conditions properly.

  • Can be used in:

    • WHERE

    • HAVING

    • JOIN ... ON conditions


? More Examples

? In HAVING clause:

SELECT department, COUNT(*) as countFROM employeesGROUP BY departmentHAVING COUNT(*) > 1 AND SUM(salary) > 90000;

? In JOIN:

SELECT *FROM employees eJOIN departments d ON e.department = d.name AND d.active = 1;

Let me know if you'd like to practice logical conditions or combine AND with NOT, OR, or subqueries!

Disclaimer for AI-Generated Content:
The content provided in these tutorials is generated using artificial intelligence and is intended for educational purposes only.
html
docker
php
kubernetes
golang
mysql
postgresql
mariaDB
sql