Database Terms - and their Meanings
WHERE is the new if
With those basics out of the way, we can start with the SQL language. First thing to learn is the SELECT command. This command is used to get the data from the database. And its used all the time.
Before we go into the code, let me introduce you to the way I write SQL code. SQL is case insensitive - so select is SELECT is SeLEcT. But I have a certain method, a certain convention, for writing SQL code. SQL keywords and functions will be in UPPER CASE. Fields will be in lower case. Most people will use lower case for table names as well - but I prefer using title case for table name.
OK - back to SELECT. Say we want to get all the information about all the characters in our database...
I am sure you have guess this already - but * stands for everything. Or all. Or the whole. Or - oh you get the idea, don't you? Maybe we don't want all the data - we just need the name and IQ - then this would be the query...
Now you want to rename the fields - you want to call the name field 'Person' and the iq field 'Intelligence' - this is what you do...
Try to execute the query - and look at the headers - you will notice the name change.
AS keyword creates an alias for the field and uses that instead of the real name. It might seem pointless now, but it is useful when you are using functions(we will get to that later).
SELECT Query Syntax
This is the general syntax of select statements...
SELECT <field names> FROM <table name>