top of page

CODING 101: SQL Basics Data Retrieval

Writer's picture: Test LeadTest Lead

To start off you may be asking what is SQL? SQL stands for structured query language. Now you may be asking how is it useful? SQL is used to access and modify information from a database. It is essential that you understand the fundamental SQL statements before moving on to the advanced actions. We will break down the different parts of the data retrieval process and then conclude with an example.

This article will cover:

  • Select command

  • From keyword

  • Where clause

  • Writing your first query

SQL Select Statement

One of the purposes of using SQL is to query or retrieve data from the database. This is done using the Select statement. This will then be followed by the columns you want to be returned. If you want all of the columns returned you can simply put “Select *”

Examples

  • Select {column name}-Selects 1 column

  • Select{column name 1}, {column name 2}, {column name 3}-Selects 3 columns

  • Select *-Selects all of the columns in the database



From Clause

Next, we will use the From clause. This will let us dictate what table we are retrieving the information from. After the Select statement, your From clause can be defined by stating the table name that contains the columns from our Select statement. This is REQUIRED whenever you are using a select statement. You can’t define columns in your Select statement without specifying what table those columns are from.

Examples

  • From {table 1}

  • From{ table 2}



Where Clause

Next, we will use the Where clause to wrap everything up. Please note the Where close is optional but still beneficial. The Where clause helps you narrow down the results from your search. The Where clause can an exact value or a range of values

Examples

  • Where {column 1} = {some value}-returns information where column 1 matches “some value”

  • Where{column 1} < {some value}-returns information where column has a value less than “some value”

  • Where{column 1} = {some value} AND {column 2} = {some other value}-returns information where column 1 matches “some value” and column 2 matches “some value”



Writing Your First Query

Now we can combine everything we learned. Remember for data retrieval the Select statement and From clause are required and the where clause is optional but helps to narrow down your results. We will be using

Examples

  • Select {column name 1} From {table name}

  • Select * From {table name} Where {column 1} = {some value}

  • Select {column name 1}, {column name 2}, {column name 3} From {table name}, Where {column 1} = {some value} AND {column 2} = {some other value}








18 views0 comments

Comments


bottom of page