Categories
Blog Posts

Basics of SQL

SQL is a query sorting language. It is used in a wide variety of applications to parse through and select information for display. SQL runs off of tables, and can pull data and information out of said tables through the most common command, SELECT.

The Select Command

This command allows the code to pull out specified entries from a table. In it’s most basic form, you can use the below command to select data from the specified table

SELECT * FROM TABLE_NAME;

In many cases, you will want to shorten the amount of data you present, down to only the essentials. You can further modify the query, by adding which fields, or headers, you want to select.

SELECT FIELD FROM TABLE_NAME;

Often, you’ll find the need to parse out unwanted data entries. To do this, you can add a conditional statement – WHERE.

SELECT FIELD FROM TABLE_NAME WHERE CONDITION;

Conditions

Conditions are simple logic gates that you can use to narrow down results. For instance, you may want to only display entries where the specified field only equals 3. To do this, you simply use the following lines.

SELECT FIELD FROM TABLE_NAME WHERE FIELD = 3;

You can also use the < or > symbols to further specify. Just remember, the alligator goes after the bigger number! There’s a whole trove of conditions for your needs. Let’s say you need to find if a number is in a array, then simply use the IN command.

SELECT FIELD FROM TABLE_NAME WHERE FIELD IN (1, 2, 3 . . .);

What about if you want to check if it’s between two numbers? Just use the BETWEEN command.

SELECT FIELD FROM TABLE_NAME WHERE FIELD BETWEEN (1, 10);

How about if a string has to start with a certain character. Just use the like command and one of the 3 string patterns, “A%” for starting with, “%A” for ending with, and “%A%” for simply possessing.

SELECT FIELD FROM TABLE_NAME WHERE FIELD LIKE “A%”;

Hopefully this easy guide to basic SQL will help you in your own, list-sorting adventures!

Categories
Tests

Hello world!

Welcome to WordPress. This is your first post. Edit or delete it, then start writing!