Posts

Group By

GROUP BY Group by clause is used to group the results of a SELECT query based on one or more columns. It is also used with SQL functions to group the result from one or more tables. Syntax for using Group by in a statement. SELECT column_name, function(column_name) FROM table_name WHERE condition GROUP BY column_name Example of Group by in a Statement Consider the following Emp table . eid name age salary 401 Anu 22 9000 402 Shane 29 8000 403 Rohan 34 6000 404 Scott 44 9000 405 Tiger 35 8000 Here we want to find name and age of employees grouped by their salaries or in other words, we will be grouping employees based on their salaries, hence, as a result, we will get a data set, with unique sal...

Having Clause

HAVING Clause Having clause is used with SQL Queries to give more precise condition for a statement. It is used to mention condition in Group by based SQL queries, just like WHERE clause is used with SELECT query. Syntax for HAVING clause is, SELECT column_name, function(column_name) FROM table_name WHERE column_name condition GROUP BY column_name HAVING function(column_name) condition Example of SQL Statement using HAVING Consider the following Sale table . oid order_name previous_balance customer 11 ord1 2000 Rahul 12 ord2 1000 Adam 13 ord3 2000 Abhi 14 ord4 1000 Adam 15 ord5 2000 Rahul Suppose we want to find the customer whose previous_balance sum is mor...
SQL Data Types The SQL data type defines a kind of value that a column can contain. In a database table, every column is required to have a name and a data type. Data Type varies from database to database. For example, MySQL supports INT but Oracle supports NUMBER for integer values . These are the general data types in SQL. Data-type Syntax Explanation Integer INTEGER The integer data type is used to specify an integer value. Smallint SMALLINT The smallint data type is used to specify small integer value. Numeric NUMERIC(P,S) It specifies a numeric value. Here 'p' is precision value and 's' is scale value. Real REAL The real integer is used to specify a single precision floating point number. Decimal DECIMAL(P,S) It specifies a decimal value. Here 'p' is precision value and ...