Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
2.6 kB
7
Indexable
Never
05/03/2024
=========================================================
Having clause:
having clause is uesd for filter the records from the group based on the given condition.
having clause is only used  with select clause.
syntax:- select column() from table_name group by column_name having condition;

ex: select count(*), item from Orders  group by item having count(*)>1;

   select count(*), item from Orders  group by item having count(*)>1 order by item desc;

when we use having ,where,order by ,group by  clause

sequence:
     where 
     group by 
     having
     order by


difference between where and having clause.

where:-1.where caluse is used to filter the data from the table in the specific condition.
       2. where clause cannot cointain aggregate function.
       3.where clause can be used without group by clause.
       4.where clause is used with select,update,delete.
       5.where clause is used before group by clause.
       



having:-1. having clause is uesd for filter the records from the group based on the given condition.
        2. having clause contain aggregate function.
        3. having clause cannot be used without group by clause.
        4. having clause is only used  with select clause.
        5. having clause is used after group by clause.


---------------------------------------------------------------------------------------------------------------------------
Alter statement:
alter statement is used to modify structure of existing table

1 Add, rename,modify,drop

alter statement is used for add ,delete modify columns in existing table

syntax:- alter table tablename add(/drop/modify/rename) column column_name datatype. 
alter table tablename rename column old_col_name to new_col_name.

use testdb;
select * from customerinfo;
desc customerinfo;
alter table customer rename to customerinfo;
alter table customerinfo add price int;
alter table customerinfo rename column address to addr;
alter table customerinfo modify price float;
alter table customerinfo drop column price;

=================================================================================================

truncate statement:

truncate table cammand is used for delete the entire data inside the table.

syntax:- truncate table tablename;
exa:

truncate table employee;

======================================================================================
Drop statement is use for delete table in the database.

syntax:
drop table tablename;
eaxa:
drop table employee;

Leave a Comment