Difference between WHERE and HAVING clauses in SQL

Difference between WHERE and HAVING clauses in SQL

What are the contrasts among WHERE and HAVING provisos? Here, we will find out about what are the likenesses and dissimilarities among HAVING and WHERE statements in SQL?

WHERE Clause:

  • WHERE Clauses can be utilized for restrictive
  • It is fundamentally to bring a specific record
  • On the off chance that we are utilizing WHERE Clauses, at that point WHERE Clauses ought to be notice before having conditions
  • WHERE Clauses can’t be actualized on gathering
  • We should actualize WHERE Clauses at whatever point condition required

Syntax:

SELECT col1,col2 FROM tablename 
WHERE col1 = value;

Example: (Table)

    Id	Full_name
    3	Anny sharma
    4	Ayesha jain
    5	Preeti jain
    6	Rahul jain

Query:

mysql> SELECT * FROM emp WHERE id = 4;

Output

    Id	Full_name
    4	Ayesha jain

HAVING Clause:

  • HAVING Clauses can likewise be utilized for restrictive
  • It is fundamentally to get a restrictive record
  • On the off chance that we are utilizing HAVING Clauses, at that point HAVING Clauses ought to be notice subsequent to HAVING Clauses
  • HAVING Clauses ought to be actualized on gathering
  • We should actualize HHAVING Clauses at whatever point condition required

Syntax:

SELECT col1,col2, ..., coln FROM tablename 
WHERE colname = value 
GROUP BY colname HAVING colname = value;

Example: (Table)

    Id	Full_name
    3	Anny sharma
    4	Preeti jain
    5	Rahul jain
    7	Anny sharma

Query:

mysql> SELECT * FROM emp 
GROUP BY id HAVING full_name = 'Anny sharma';

Output

    Id	Full_name
    3	Anny sharma
    7	Anny sharma

DURGESH

I Love python, so I like machine learning a Lot and on the other hand, I like building apps and fun games I post blogs on my website for Tech enthusiast to learn and Share Information With The World.

Leave a Reply

Your email address will not be published. Required fields are marked *

19 − fourteen =

Recent Content