Quantcast
Channel: CodeProject – Essential SQL
Browsing all 162 articles
Browse latest View live

Image may be NSFW.
Clik here to view.

How to Write SQL – Understand Database Table Meanings and Relationships – Step 1

The first step to write SQL is to understand the database tables meanings and relationships.  This is important, as complex queries often span more than one table.  Knowing the purpose of the table and...

View Article


Write SQL – Formulate your Question – Step 2

To write SQL it is important to understand the question you wish to ask the database.  I know this seems pretty obvious, but you would be surprised how many people get tripped up on this step.  Some...

View Article


Image may be NSFW.
Clik here to view.

Write SQL – Write the Query – Step 3

To write sql, we’ll take all the information we’ve compiled in the previous articles and map it to the appropriate SELECT clause.  The series starts with this introductory article. All the examples for...

View Article

Image may be NSFW.
Clik here to view.

A Case Study on How to use Joins, Subqueries, and Unions to Combine Data in SQL

A reader recently asked me to help them solve a problem combining data from multiple tables into a single result.  What was interesting was that the solution used the three ways to combine data that we...

View Article

Image may be NSFW.
Clik here to view.

How do the SQL DISTINCT and TOP SELECT Clauses Work Together to Generate...

This article is inspired by a series of questions that one of my readers, Nan, recently sent me regarding DISTINCT, TOP, and ORDER BY. All the examples for this lesson are based on Microsoft SQL Server...

View Article


Image may be NSFW.
Clik here to view.

What is the Difference between a Primary Key and a Foreign Key?

In this article we learn the difference between a primary and a foreign key, and why both are important to maintaining a relational database structure. All the examples for this lesson are based on...

View Article

Image may be NSFW.
Clik here to view.

Using OFFSET and FETCH with the ORDER BY clause

In this article we explore the OFFSET and FETCH clauses.  OFFSET and FETCH are used in conjunction with the SELECT statement ORDER BY clause to provide a means to retrieve a range of records.  The...

View Article

Image may be NSFW.
Clik here to view.

What is the Differenence between TOP and OFFSET & Fetch?

Both TOP and OFFSET & FETCH can be used to limit the number of rows returned.  OFFSET and FETCH can return similar results to top, but there are differences which may influence which method is best...

View Article


Image may be NSFW.
Clik here to view.

Using Conditional Logic in SQL with CASE Expression

The main purpose of a CASE expression is to return a value based on one or more conditional tests.  CASE expressions can be used anywhere in a SQL statement an expression is allowed. Though a truly an...

View Article


Image may be NSFW.
Clik here to view.

Commonly used SQL Server Data Types

In SQL the columns of a table are defined to store a specific kind of value such as numbers, dates, or text; these are called data types.  With over thirty types of SQL server data types to choose...

View Article

Image may be NSFW.
Clik here to view.

How can I find Duplicate Values in SQL Server?

In this article find out how to find duplicate values in a table or view using SQL.  We’ll go step by step through the process.  We’ll start with a simple problem, slowly build up the SQL, until we...

View Article

Image may be NSFW.
Clik here to view.

Introduction to SQL Server’s Built-In Conversion Functions

SQL server uses data types to store a specific kind of value such as numbers, dates, or text in table columns and to use in functions, such as mathematical expressions. One issue with data types is...

View Article

Image may be NSFW.
Clik here to view.

Built-In Functions (SQL Server)

Built-In functions are used in SQL SELECT expressions to calculate values and manipulate data.  These functions can be used anywhere expressions are allowed.  Common uses of functions include to change...

View Article


Image may be NSFW.
Clik here to view.

Introduction to SQL Server’s Built-In Logical Functions

Logical functions provide a way to use logical conditions to display one of several values.  You can use logical functions to test a field’s value such as gender (M or F) and display another...

View Article

Image may be NSFW.
Clik here to view.

Introduction to SQL Server’s Mathematical Functions

Math Rocks! SQLServer includes many mathematical functions you can use to perform business and engineering calculations.  Many of these aren’t used in typical day-to-day operations; however, there are...

View Article


Image may be NSFW.
Clik here to view.

What is the Difference between a Join and Subquery?

Joins and subqueries are both be used to query data from different tables and may even share the same query plan, but there are many differences between them.  Knowing the differences and when to use...

View Article

Image may be NSFW.
Clik here to view.

Introduction to SQL Server’s Common String Functions

The built in SQL String functions make it possible for you to find and alter text values, such as VARCHAR and CHAR datatypes, in SQLServer.  Using these functions you can alter a text value such as...

View Article


Image may be NSFW.
Clik here to view.

What Is the Difference Between a Join and a UNION?

Both Joins and UNIONS can be used to combine data from two or more tables.  Read this article to find out each command’s strengths and when to use them. To get the most of this and our other lessons be...

View Article

Image may be NSFW.
Clik here to view.

What is the Difference between Inner and Outer Joins?

Both inner and outer joins can be used to combine data from two or more tables; however, there are some key differences!  Read this article to find out each command’s strengths and when to use them. To...

View Article

What is the Difference Between Cast and Convert?

In this article we’re going to explore the CAST and CONVERT functions to understand whether there are any significant differences worth knowing when we want to convert data from one type to another....

View Article
Browsing all 162 articles
Browse latest View live