answersLogoWhite

0


Best Answer

They do completely different things, so I'm not sure why you grouped them into one question.

ORDER BY is pretty straightforward: it arranges the results to be in alphabetical or numerical order (or the reverse, if you use ORDER BY column_name DESC). Without it, you get the results in whatever order the database feels like giving them to you, which can and probably will change as new rows are added.

The HAVING clause is a little trickier. It's used to restrict the selection based on grouped results (in other words, you can think of it as a variation on the WHERE clause). It can be used to e.g. find duplicates:

SELECT Should_Be_Unique_ID

FROM MyTable

GROUP BY Should_Be_Unique_ID

HAVING COUNT(*) > 1;

User Avatar

Wiki User

10y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Why you use order by and having clause in sql?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Statistics

List two reasons why null values might be introducedin database?

1. special requirements for its use in SQL joins. 2. special handling required by aggregate functions and SQL grouping operators


What group function can be used to perform a count that includes NULL values?

You can not group a NULL value natively. You can however transform the NULL into so other unique value; dynamically, without writing this value to the database; and group by this. You would accomplish this by implementing a coalesce T-SQL expression For example lets say the MiddleName field is NULL in many cases and you want to to group by these.. You might want to turn this NULL into say an * for purposes of giving a value that you can group by. Now you can group by all MiddleName entries and also use a where clause to excluded those values <> * giving you a sub grouping of those records ONLY having null. The SQL command would look something like this: SELECT coalesce(MiddleName, '*') FROM YourTableNameHere WHERE MiddleName LIKE '*' GROUP BY MiddleName The coalesce returns the first NON NULL value in the chain(you can have more than two values). In the above example you will get the MiddleName if there is one and an * if the database value is NULL. This is a SELECT so there is NO update to the database.


What is teradata in data warehousing?

Teradata is a RDBMS system like Oracle or SQL Server but designed specifically for use in data warehousing. Data Warehouses contain extremely large amounts of data that normal RDBMS systems like oracle or sql server cannot handle comfortably. They may eventually be able handle the data but their performance may not be the best. Teradata is a system that is specifically designed for handling such extremely high volumnes of data.


Why you use indexes in SQL?

It provides a better and faster method to search a particular item you are looking for. When you issue a select statement to have a particular item with some condition, it searches the whole DB to get the answer for you. Instead if you have some indexes to it, the searching is done faster.


Write a SQL statement to show the warehouse and average QuantityOnHand of all items stored in a warehouse managed by 'Smith' Use a subquery?

SELECT Warehouse, AVG(QuantityOnHand) AS QuantityOnHand FROM INVENTORY WHERE Warehouse IN (SELECT Warehouse FROM WAREHOUSE WHERE Manager = 'Smith') GROUP BY Warehouse;

Related questions

Can a having clause and a where clause be used together in a SQL query?

Yes, you can use a having clause and a where clause together in an SQL query. select emp_dept, sum(value) total_value, count(1) sales from all_sales where emp_dept in ('fashions','stereos','cosmetics') group by emp_dept having sum(value) > 125000


What is use of IN clause and between clause in sql?

It allows you to easily test if an expression is within a range of values (inclusive).


Why do people use qbe?

QBE (or query-by-example) is often a quick method of creating simple SQL queries, especially by users who are not particularly SQL-savvy. Instead of having to remember specific SQL syntax, the user builds the query by selecting tables and fields from a display and entering WHERE and GROUP BY clause specifics in a fill-in-the-box manner.


What is the use of the SQL sort?

The use of sorting information in SQL is to organize database query results. Typically the data can be sorted in either ascending or descending order. The "Order By" command can be used to sort data in SQL by multiple columns.


How does an individual use an SQL Group By Clause?

An individual uses an SQL Group by Cause simply by placing the Cause first. This is the easiest and most streamlined way to perform such a task. A task that should always be done.


Which SQL command would you use to retrieve a record or records from the database?

You would use the SELECT statement to retrieve a record or records from the database. Additionally, you can use WHERE clause to specify conditions for the retrieval.


How do you filter in a database?

While retrieving data from a database, we use SQL (Structured Query Language) language which enables developers to query data. A SQL Select statement which retrieves data from database has a WHERE clause where we can add criteria to filter data based on field values


How do you use SQL?

You use SQL by issuing commands to an SQL server, either directly by you or by a program you are using.


Which statement should you use to delete all rows in a table without having the action logged in SQL?

Drop table statement


When you are pulling or extracting information out of the database with a query - you can use to set conditions that must be met for a record to be displayed?

To set conditions when querying a database, you can use the WHERE clause in your SQL query. This clause filters the results based on specified conditions. You can combine multiple conditions using logical operators such as AND, OR, and NOT to further refine your query results.


Difference between sql and sql plus?

SQL*PLUS is a interface between user and Oracle database. It Provide an environment to use the SQL which is a query language to communicate with oracle database


What are SQL data types used for?

There are many purposes behind 'SQL' data types. The most common use of 'SQL' is with website programming and hosting services, as well as HTML coding.