Wednesday, April 13, 2011

SQL

When I'm teaching junior SysAdmins how to use SQL I've found it very helpful to focus on the basics. Then, after they've after they've grasped those, I build upon them. Here's an example.

A basic concept in working with databases is learning how to obtain data from it. The standard ways of accomplishing this is by using the SELECT statement. Here's an example-

SELECT first_name, last_name FROM employees;

This statement means display(SELECT) fields of data(first_name, last_name) FROM a table(employees);


Let's build upon what we now know. Let's filter the results of the preceeding sql statement to make the results more precise. To do this we will use a WHERE clause.

SELECT first_name, last_name FROM employees WHERE last_name = 'Johnson';

Now we've used the WHERE clause to display a subset of the data. In this example, we're displaying only employees whose last name is Johnson, instead of all employees.

No comments: