Good SQL Questions

Here is a list of good questions I’ve been asked by my students in class or via email.

Whether you’re looking to find out the difference between of primary an foreign key or want to know what is a data dictionary, you’ll find answers to many common problems.

If you have a question that I haven’t answered, please ask! You can contact me here. I’m always looking to see what you guys need helps with, as it helps me learn! I love helping!

All the examples for this lesson are based on Microsoft SQL Server Management Studio and the sample databases AdventureWorks and WideWorldImporters. You can get started using these free tools using my guide Getting Started Using SQL Server

Latest Posts

  • Window Functions vs Group By Queries?
    ,

    ·

    Window Functions vs Group By Queries?

    In this article let’s look at window functions vs GROUP BY queries. We’ll do so by looking at how each statement works and giving examples. Though you can use both GROUP BY and window functions to create summary values, the way SQL includes the results are different. Let’s first look at how GROUP BY does…

  • What are the Top Ten Databases?
    ,

    ·

    What are the Top Ten Databases?

    Everyone has their favorite DBMS, is your favorite one of the top databases? Though some non-relational products have entered the top ten, the relational paradigm remains firmly entrenched in the database world.  However specialized database types such document store databases and wide column stores are gaining in popularity to become top databases. Top of the…

  • Ten Things a Junior DBA Should Learn
    ,

    ·

    Ten Things a Junior DBA Should Learn

    There is more to being a Junior DBA than knowing SQL.  The DBA works at the intersection of the database, server, operations group, and developers.  A DBA must understand concepts from all these facets of IT as well as be able to draw upon knowledge of their production environment to troubleshoot performance, hardware, and software…

  • What is a SQL Trigger?
    ,

    ·

    What is a SQL Trigger?

    What is a Database Trigger? A SQL trigger is special stored procedure that is run when specific actions occur within a database.  Most database triggers are defined to run when changes are made to a table’s data.  Triggers can be defined to run instead of or after DML (Data Manipulation Language) actions such as INSERT,…

  • What is the Difference between TOP and OFFSET & Fetch?
    ,

    ·

    What is the Difference 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 for you to use in your given situation. All the examples for this lesson are based on Microsoft SQL…

  • Inner Join vs Outer Join Clauses
    ,

    ·

    Inner Join vs Outer Join Clauses

    Its is easy to get confused between inner join vs outer join clauses. Both inner and outer joins are 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 get the most of this and…

  • Primary Key vs Unique Key – What is the Difference?
    ,

    ·

    Primary Key vs Unique Key – What is the Difference?

    Primary Key vs Unique Key. It really not about one or the other. You actually may need both a primary key and unique key in your table. In this article we learn the difference between a primary key and unique key, and why both are important to maintaining a relational database structure. All the examples…

  • Is it possible to use Joins, Subqueries, and Unions on Multiple Tables?
    , ,

    ·

    Is it possible to use Joins, Subqueries, and Unions on Multiple Tables?

    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 have recently covered, namely:  joins, set operators, and subqueries. Given the comprehensive nature of this problem I thought it…

  • What Is the Difference Between a Join and a UNION?
    , ,

    ·

    What Is the Difference Between a Join and a UNION?

    Use joins and UNIONS 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 are sure to practice using the examples! All the examples for this lesson are based on Microsoft SQL Server…

  • What is the Difference between TRUNCATE and DELETE?
    ,

    ·

    What is the Difference between TRUNCATE and DELETE?

    In SQL Server there are a couple a ways you can delete rows from a table.   You can use the TRUNCATE and DELETE command.  Though the end result of both commands is the same, there are very important differences you should know about. Let’s explore their differences and learn What is the TRUNCATE command in SQL.…

  • SQL ACID Database Properties Explained
    ,

    ·

    SQL ACID Database Properties Explained

    What are the ACID Database Properties? The ACID properties define SQL database key properties to ensure consistent, safe and robust database modification when saved. ACID is an acronym that helps to remember the fundamental principles of a transnational system. ACID stands for Atomic, Consistent, Isolation, and Durability.  Here are some informal definitions: Atomic – Transaction acting on…

  • What is the Difference Between Merge and Update?
    ,

    ·

    What is the Difference Between Merge and Update?

    When modifying one table based on the contents of another it may be tempting to simply use the merge statement, but before you throw away all other forms of modifying data, I think it’s important for you to know the difference between merge and update. What is the Difference Between MERGE and UPDATE? Both the…

  • Can I have a CASE Statement in the WHERE Clause?
    ,

    ·

    Can I have a CASE Statement in the WHERE Clause?

    I’m commonly asked whether whether I can have a CASE Statement in the WHERE Clause. There are a number of examples using the CASE WHEN construct in SQL, such as the SELECT columns or in ORDER BY clauses, but we tend to forget CASE can be used wherever an expression is expected. Where Can I…

  • SQL DISTINCT and TOP in Same Query
    ,

    ·

    SQL DISTINCT and TOP in Same Query

    This article is inspired by a series of questions that one of my readers, Nan, recently sent me regarding SQL DISTINCT, TOP, and ORDER BY. All the examples for this lesson are based on Microsoft SQL Server Management Studio and the AdventureWorks2012 database.  You can get started using these free tools using my Guide Getting Started…

  • Use SQL Server to Sort Alphanumeric Values
    ,

    ·

    Use SQL Server to Sort Alphanumeric Values

    Sort Alphanumeric Values with SQL Server Recently a reader asked me how to sort an alpha numeric field in SQL in natural order.  Alphanumeric values are commonly found and don’t sort naturally using numeric methods. When we have a numeric fields we expect values to be sorted in ordinal order, for example: 1,2,5,7,10,11,15,20,21 However when…

  • What is a Database NULL Value?
    ,

    ·

    What is a Database NULL Value?

    What is a Null Value? In databases a common issue is what value or placeholder do you use to represent a missing values.   In SQL, this is solved with null.  It is used to signify missing or unknown values.  The keyword NULL is used to indicate these values.  NULL really isn’t a specific value as much as it…

  • Database Indexes Explained
    ,

    ·

    Database Indexes Explained

    A database index allows a query to efficiently retrieve data from a database.  Indexes are related to specific tables and consist of one or more keys.  A table can have more than one index built from it.  The keys are a fancy term for the values we want to look up in the index.  The…

  • What is a Database Table?
    ,

    ·

    What is a Database Table?

    A relational database is made up of several components, of which the table is most significant.  The database table is where all the data in a database is stored, and without tables, there would not be much use for relational databases. Overall Structure of a Database Table A database consists of one or more tables. …

  • Database Management System Main Parts
    ,

    ·

    Database Management System Main Parts

    The main objective of a database management system is to store, retrieve, and process data.  In order to do this in a safe and efficient manner, several major components work together to achieve this aim.  They are:

  • What are the Major Part of a SQL DB?
    ,

    ·

    What are the Major Part of a SQL DB?

    A SQL database is used to store and retrieve data.  The database is housed in a database server and largely controlled by a database management system.  All SQL databases, whether they MS SQL Server, MySQL, Oracle, or Progress have several components in common.  They are: Tables Indexes Views Stored Procedures Triggers It is these various…