Showing entries 1 to 10 of 1197
10 Older Entries »
Displaying posts with tag: sql (reset)
How to limit the SQL query result set to Top-N rows only

Introduction In this article, we are going to see how we can limit the SQL query result set to the Top-N rows only. Limiting the SQL result set is very important when the underlying query could end up fetching a very large number of records, which can have a significant impact on application performance. Why limit the number of rows of a SQL query? Fetching more data than necessary is the number one cause of data access performance issues. When a given business use case is developed, the amount of data available... Read More

The post How to limit the SQL query result set to Top-N rows only appeared first on Vlad Mihalcea.

SQL Check Constraint Example | Check Constraint In SQL Tutorial

SQL Check Constraint Example | Check Constraint In SQL Tutorial is today’s topic. Check constraint is used for specifying the predicate that every tuple must satisfy in a relation i.e. it is used for limiting the values that a column can hold in a relation. It is used for giving a condition to check the value to be entered into a record. If the condition results in false then that value will not be added to the record.

SQL Check Constraint

The CHECK constraint is used to limit the value range that can be placed in a column.

If you define a CHECK constraint on a single column it allows only certain values for this column.

If you define a CHECK constraint on a table it can limit the values in certain columns based on values in other columns in the row.

Some key points of SQL Check Constraint are following.

  1. Check constraint cannot be defined inside the …
[Read more]
SQL String Functions Example | String Functions In SQL

SQL String Functions Example | String Functions In SQL is today’s topic. String functions are used for manipulating the strings. Here, in SQL, we provide the string as input and then after applying string functions desired manipulated string is obtained. Let’s discuss all the string functions with proper explanation and examples.

SQL String Functions

See the following String Functions.

#ASCII()

The ASCII function is used for finding the ascii value of the character i.e. the numeric value. If more than one character is inserted within the function then the leftmost character value will be displayed. Here, we are using SQL SELECT Statement.

#Syntax

SELECT ASCII('ab');

#Output

97

#CHAR_LENGTH()

The char_length() function is used for finding the length of a word.

[Read more]
SQL NULL Functions Example | IFNULL(), ISNULL(), COALESCE(), NULLIF

SQL NULL Functions Example | NULL Functions in SQL Tutorial is today’s topic. The SQL Term NULL represents any value that is missing. It is described as a blank in a table under any column. One should remember that a NULL value is something different from Zero and Blank Spaces. NULL functions are the functions which are used for replacement of NULL values.

SQL NULL Functions

We will see these IFNULL(), ISNULL(), COALESCE(), NULLIF functions.

Let’s discuss it one by one:

Consider the table: (Employee)

Emp_id Emp_name City State Salary Phone Alternate Phone
101 …
[Read more]
SQL AND OR NOT Operator Example Tutorial

SQL AND OR NOT Operator Example Tutorial is today’s topic. The SQL AND, OR and NOT operators are used for filtering the records based on one or more conditions. The AND, OR operators are used with where clause. It can also be combined with the NOT operators. The AND OR operator is also known as Conjunctive operators.

SQL AND OR NOT Operator

AND, OR operator is also known as Conjunctive operators.

  1. The AND operator displays the record only if the conditions separated by AND operator results in True. All the conditions separated by AND operator should be true; otherwise, it will not display all the records.
  2. The OR operator displays the records if either of the …
[Read more]
PL/SQL If Else Statement Example | PL/SQL If Else Tutorial

PL/SQL If Else Statement Example | PL/SQL If Else Tutorial is today’s topic. Decision making is an important part when it comes to programming languages, unlike other programming languages such as C, C++, Java, Python, etc. SQL also has decision making statements. Decision-making statements in programming languages are used to decide the direction of the flow of the statements to be executed. Decision-making statements are those who will decide the flow-control of SQL statements based on the conditions.

PL/SQL If Else Statement

Types of If-Else statements available in PL/SQL is:

  1. If then statement
  2. If then else statement
  3. Nested if-then statements
  4. If-then-else if-then-else ladder

Let’s understand all the types mentioned above with examples.

#If then statement

If then the statement is as simple as its name …

[Read more]
SQL Stored Procedure Example | Stored Procedure In SQL Tutorial

SQL Stored Procedure Example | Stored Procedure In SQL Tutorial is today’s topic. A stored procedure is the prepared SQL code that is used to save time and can be reused over and over again. This code is stored in the database and helps to get the required output by passing parameters. These stored procedures are used in PL/SQL or SQL SERVER. PL/SQL is a block-structured query language that helps developers to combine the power of SQL with procedural statements.

SQL Stored Procedure

A stored procedure is the prepared SQL code that you can save so that the code can be reused over and over again.

So if you have the SQL query that you write over and over again, save it as the stored procedure, and then call it to execute it.

You can also pass parameters to a stored procedure so that the stored procedure can act based on the parameter value(s) that is passed.

The procedure can be a …

[Read more]
SQL Subqueries Example | Subqueries In SQL Tutorial

SQL Subqueries Example | Subqueries In SQL Tutorial is today’s topic. A subquery is known as a nested query within another SQL query and is embedded within the where clause. It is usually added within the where clause of another SQL SELECT statement. It is used to return data, which will further be used in the main query as a condition to restrict the data also to be retrieved. It can be used with the SELECT, INSERT, UPDATE and DELETE statements along with the …

[Read more]
SQL ORDER BY RANDOM

Introduction In this article, we are going to see how we can sort an SQL query result set using an ORDER BY clause that takes a RANDOM function provided by a database-specific function. This is a very handy trick, especially when you want to shuffle a given result set. Note that sorting a large result set using a RANDOM function might turn out to be very slow, so make sure you do that on small result sets. If you have to shuffle a large result set and limit it afterward, then it’s... Read More

The post SQL ORDER BY RANDOM appeared first on Vlad Mihalcea.

SQL Aliases Example | Alias In SQL Tutorial

SQL Aliases Example | Alias In SQL Tutorial is today’s topic. Aliases are the temporary names that exist for a particular query. It is used for better understanding and reducing the workload of writing big column names. Aliases are the temporary name and the changes made with the column name while retrieving does not reflect in the original database.

SQL Aliases Example

An Alias is a shorthand for the table or column name. Aliases reduce the amount of typing required to write the query. Complex queries with the aliases are generally easier to read. Aliases are useful with JOINs and …

[Read more]
Showing entries 1 to 10 of 1197
10 Older Entries »