Can you use HAVING command without any aggregate function in SQL?

Question

A bit tricky, do give a try

solved 3
Xtramous 55 years 27 Answers 5660 views Contributor 0

Answers ( 27 )

  1. Sorry it a private answer.

  2. select pub_id, count(pub_id)
    from publishers
    having pub_id < "1000"
    pub_id
    —— —————-
    0736 3
    0877 3

  3. select id, count(id)
    from book
    having id < "10";

  4. yes, we can use Having command without an aggregate function .in that case it will work like a simple where clause.

  5. If no group by clause is used then it can act like a simple where clause
    e.g ;- select count(id) from table A
    having id < "400"

  6. Yes we can. It will work like a where clause

    1

    If no group by is provided, having will act like where clause

  7. If there is no aggregate function having works like where

  8. Having command can be used without aggregate function , It will act like a where clause.

  9. If there is no aggregate function in sql, having works like a where clause.

  10. HAVING is filtering the groups. If you don’t have GROUP BY clause, all rows form a single group. Thus, Having command can be used without aggregate function, It will act like a where clause.

    SELECT SUM(spending) as totSpending
    FROM budget_data
    HAVING SUM(spending) > 200000;

  11. yes having clause can be used without aggregate function in query it will just behave the same as where clause.

  12. The question is ‘Can you use HAVING command without any aggregate function in SQL?’

    “Without any aggregate function”

    Having clause cannot be used without aggregate function.
    It is right that it works like a WHERE clause when the GROUP BY clause is not used in the query.

    But, to query HAVING CLAUSE without GROUP BY clause, there should be an aggregate function in the SQL Query.
    ****************************
    Example:
    SELECT points_earned
    FROM Game1
    HAVING points_earned > 50;

    ERROR: column “Game1.points_earned” must appear in the GROUP BY clause or be used in an aggregate function
    LINE 1: SELECT points_earned
    ^

  13. Yes, We can use Having without any aggregate function , but in that case it simply act like a where clause.

  14. You can use the having clause with the Transact-SQL extension that allows you to omit the group by clause from a query that includes an aggregate in its select list. These scalar aggregate functions calculate values for the table as a single group, not for groups within the table.

    the group by clause is omitted, which makes the aggregate function calculate a value for the entire table. The having clause excludes non-matching rows from the result group.

    select id, count(id)
    from books
    having id < "1000"

  15. The HAVING clause can also be used without aggregates.
    The following query groups the products, and then restricts the result set to only those groups for which the name starts with B.

    SELECT Name FROM Products GROUP BY Name HAVING Name LIKE ‘B%’;

  16. Yes, we can use HAVING without aggregate function. But in this we perform aggegate function on one attribute (it calculates the value for a table as a single group)

    example :

    SELECT id, COUNT(id)
    from TABLE
    HAVING id < "2000"

  17. Yes we can use HAVING without aggregate function also. the thing is we consider whole table as a single group instead of creating multiple groups

    example.

    SELECT id, COUNT(id)
    FROM
    Table_name
    HAVING
    id < "2000";

  18. SELECT ID, COUNT(ID)
    FROM employees
    HAVING ID < 7 (Work as a normal where clause since the whole data is considered as a single group)

  19. Yes, we can use HAVING without aggregate function. But in this we perform aggegate function on one attribute (it calculates the value for a table as a single group)

    example :

    SELECT id, COUNT(id)
    from TABLE
    HAVING id < "2000"

  20. A query with a HAVING clause should also have a group by clause.If you omit group by, all the rows not excluded by the where clause return as a single group.
    If you are using Having command without an aggregate function in that case it will work like a simple where clause.

  21. Yes HAVING Command works like WHERE without any aggregate functions.

  22. Though having is used with group by function but if we use having without using group by function it will act in the same way as the where clause does.

  23. Though having is used with group by function but if we use having without using group by function it will act in the same way as the where clause does.This means having function without aggregates is same as where clause .

  24. Having function without aggregates is same as where clause .

  25. Having clause without aggregate function it will behave like a where clause

  26. Yes, we can use having command without any aggregate function in SQL as well.

    Eg.
    The following query groups the products, and then restricts the result set to only those groups for which the name starts with K.

    SELECT Name
    FROM Products
    GROUP BY Name
    HAVING Name LIKE ‘K%’;

Leave an answer

Browse
Browse