Reading from a data source

Last time we listed out several things that can be done with or to a data source.

Now all of the examples we’ll be using in this series will use a database as a data source. It will allow us to discuss another of my favorite topics — SQL — while we talk about what we can do to a data source like we listed here.

And we’ll start with the first in our series — Read data from it.

This is probably the most straight forward. We just simply read what is in the database table. In basic SQL Syntax, it would look like the following:

SELECT * FROM [SampleTable];

In our example, the database table is called SampleTable. The word SELECT says that we want to read (or view) the SampleTable. Finally, the asterisk (*) means that we want to see all of the columns from the SampleTable.

Hopefully, there won’t be too many times that someone will want to look at an entire table – especially if there are millions of rows in the table or hundreds of columns! Just imagine trying to look at an Excel spreadsheet with hundreds of columns! It gets old rather fast, doesn’t it? Especially if you’re trying to look at the data in multiple places that aren’t right next to each other, right?

So, the WHERE clause to the rescue! If we change our above code to the following, we can see a much smaller section of the table. One that is much more palatable. 😊

SELECT FirstName, MiddleInitial, LastName, DateOfBirth FROM [SampleTable] WHERE LastName = ‘Wilkie’;

As you’ll notice, if you’ll compare this latest version with the version before, it’s eerily similar. We replaced the asterisk with the specific columns FirstName, MiddleInitial, LastName, and DateOfBirth. Now these columns have good names – unlike you’ll find in some database tables – so you can feel certain of what data the columns have in them. The word WHERE tells us that we only want rows with a specific value. In this case, we only want to see where the column LastName has a value of Wilkie – the last name of your favorite blog author, right? 😊

Now, there are many other things that we can do with the SELECT statement – like grabbing data from 2 or more tables – but that we’ll leave for yet another blog post.

4 comments

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.