Quick basics of SQL?

Crone

Bronze Baronet of the Realm
9,709
3,211
A job opportunity has come available, and they've put it out internally at my work to find someone. It's a techie kind of job and a big portion of the positions responsibilities is writing sql scripts to create custom reports.

Before I go into any interviews I was looking for recommendations on websites or books that would give me a high level over view of sql programming.

The company will teach me sql, but I thought it'd be nice if I could throw some key words out in an interview to show I at least know what it is.

Any tips or suggestions are greatly appreciated!
 

Tenks

Bronze Knight of the Realm
14,163
606
Think of SQL as more a DSL (domain specific language.) W3 schools has some really nice tutorials. I'll give a brief tutorial assuming you know the absolute bare basics of databases such as tables, columns, primary and foreign keys.

First there is your main selector word. That is, shockingly, SELECT. So something likeSELECT * FROM Employeeswould get all entries for the Employees table. This can get more difficult when you need to add something SQL calls JOIN. There are three main flavors but for the most part you'll need to only deal with full inner joins. Outer joins (left and right varieties) are if some of the items you are joining on can be null. Joins are used to connect tables via their relationships. Generally you'll connect one table's primary key to another table's foreign key. Something likeSELECT Employees.Name, Addresses.PhoneNumber FROM Employees JOIN Addresses ON Employee.AddressID=Address.IDThis would select the employee's name and their phone number, which is stored in a seperate table.

Next there are your DDL (data definition language) and your DML (data manipulation language.) DDL's primary responsability is your INSERT statements. It is pretty much as you'd expect. You insert a bunch of information into a database row. Such asINSERT INTO Employees (id,Name,JobTitle) VALUES (1,'John Doe','Manager')Pretty self explanitory. It will insert an employee, John Doe into the table with the role of Manager.

Then there is DML (data manipulation language) and your DML is mostly in charge of the UPDATE statement. Again pretty much explains itself. You update a row generally from the primary key. Like lets say John Doe gets a promotion.UPDATE Employees SET JobTitle = 'Senior Manager' WHERE id = 1

There is obviously way more than that. I just gave one, and the primary function, of the DDL and DML but there is, obviously more. It should give you some key terms to search google. I'm quite profecient in usage of SQL, database management and database design so I can try and help you out. Once you 'click' with RDBMS (relational database management systems) design and management of these databases is actually quite simple.

http://www.w3schools.com/sql/<-- IMO, best SQL reference online

.
 

Crone

Bronze Baronet of the Realm
9,709
3,211
Thank you Tenks! It seems all pretty self explanatory. This would assume that the database you are trying to pull information from is setup well? I can imagine that causing a lot of issues if you are trying to pull from fields that are not titled correctly.

I'll start reading that site so I can go into the interviews with some knowledge!
 

Ortega

Vyemm Raider
1,146
2,517
Best bet is to downloadSQL ExpressandManagement Studio.

After you get those setup gohereand download the 2008R2 version of the Adventure Works database.

This should be a decent setup for you to test queries, build views, or whatever. Quick tip I have for you is to be careful when updating or deleting rows. I generally like to lead off with a simple select statement and validate that I'm getting the right rows before I modify or remove them.

Also not to sound like a jerk but it gets a lot more complicated than making sure there are no typos. I would definitely tinker around with it for a while and make sure it's something you'd like to do.
 

Tenks

Bronze Knight of the Realm
14,163
606
Thank you Tenks! It seems all pretty self explanatory. This would assume that the database you are trying to pull information from is setup well? I can imagine that causing a lot of issues if you are trying to pull from fields that are not titled correctly.

I'll start reading that site so I can go into the interviews with some knowledge!
Well part of the DDL is your database create statements and table creates / column definitions. But generally you'll use a UI to set that all up. I'm not sure what you mean by fields not titled correctly because you just select the column regardless of it's title. The Employee's column name could be "foobar" for their title and it would operate the same.
 

Crone

Bronze Baronet of the Realm
9,709
3,211
Well it's not all I would be doing. If I was coding sql all day long I don't think I'd enjoy it, but there will be other things.

Thank you guys a lot for the information. I started doing some of the sql tutorials last night and that gave me a lot of information.
 

Ravishing

Uninspiring Title
<Bronze Donator>
8,452
3,577
Sounds like some of what I do at my work: Create Crystal Reports using data from SQL database. Are your reports made via Crystal Reports?
I self taught myself both. Best bet is to just start building a report and tackle each problem as you get to them. A lot of times you can do everything through Crystal without needing much (if any) SQL programming knowledge at all, other times you'll be in SQL writing complex scripts ... just depends on the task.