开发者社区> 问答> 正文

What are the different Clauses used in SQL?

What are the different Clauses used in SQL?

展开
收起
1780169608831412 2021-10-16 14:22:56 543 0
1 条回答
写回答
取消 提交回答
  • 网络规划设计师、敏捷专家、CISP、ITSS服务经理、ACA全科目、ACP4项、ACE、CBP、CDSP、CZTP等。拥有 PRINCE2 Foundation/Practitioner、CCSK、ITIL、ISO27001、PMP等多项国际认证。 专利5+、期刊10+、知识产权师。核心期刊审稿人。

    WHERE Clause: This clause is used to define the condition, extract and display only those records which fulfill the given condition.

    Syntax:

    SELECT column_name(s) 
     FROM table_name 
     WHERE condition;
    
    

    GROUP BY Clause: It is used with SELECT statement to group the result of the executed query using the value specified in it. It matches the value with the column name in tables and groups the end result accordingly.

    Further reading => MySQL Group By Tutorial

    Syntax:

    SELECT column_name(s)
     FROM table_name
     GROUP BY column_name;
    
    

    HAVING clause: This clause is used in association with the GROUP BY clause. It is applied to each group of results or the entire result as a single group. It is much similar as WHERE clause but the only difference is you cannot use it without GROUP BY clause

    Syntax:

    SELECT column_name(s) 
     FROM table_name 
     GROUP BY column_name 
     HAVING condition;
    
    

    ORDER BY clause: This clause is used to define the order of the query output either in ascending (ASC) or in descending (DESC). Ascending (ASC) is set as the default one but descending (DESC) is set explicitly.

    Syntax:

    SELECT column_name(s) 
     FROM table_name 
     WHERE condition 
     ORDER BY column_name ASC|DESC;
    
    

    USING clause: USING clause comes in use while working with SQL JOIN. It is used to check equality based on columns when tables are joined. It can be used instead of the ON clause in JOIN.

    Syntax:

    SELECT column_name(s) 
     FROM table_name 
     JOIN table_name 
     USING (column_name);
    
    2021-10-16 15:14:13
    赞同 1 展开评论 打赏
问答分类:
SQL
问答标签:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
SQL Server 2017 立即下载
GeoMesa on Spark SQL 立即下载
原生SQL on Hadoop引擎- Apache HAWQ 2.x最新技术解密malili 立即下载