views:

486

answers:

12

Looking at a job descriptions where "advanced SQL" is a requirement. I can write basic queries as well as anyone, and have worked with MySQL databases in a professional setting, but what would I be getting into with these jobs, if I were to be hired? What are examples of advanced SQL and where am I along the scale of SQL noob to SQL master?

+1  A: 

SELECT ... HAVING ... is a good start. Not many developers seem to understand how to use it.

Ignacio Vazquez-Abrams
as in "SELECT jobs HAVING (salary > a_lot) and (sql_skill <= mine)"? heh
DarenW
Not... quite :P
Ignacio Vazquez-Abrams
HAVING goes with GROUP
Cruachan
A: 

I suppose subqueries and PIVOT would qualify, as well as multiple joins, unions and the like.

Robert Harvey
+6  A: 

I would expect:

  • stored procedure creation and usage
  • joins (inner and outer) and how to correctly use GROUP BY
  • performance evaluation/tuning
  • knowledge of efficient (and inefficient) ways of doing things in queries (understanding how certain things can affect performance, e.g. using functions in WHERE clauses)
  • dynamic SQL and knowledge of cursors (and IMO the few times they should be used)
  • understanding of schema design, indexing, and referential integrity
Joe
i agree with some of these but in my experience most of what you list is actually regarded as beyond advanced. The performance tuning and schema tend to be separately-valued skills in addition to advanced querying.
Paul Sasik
"Beyond advanced" sounds intriguing. Yet these all seem like concepts I either already at least halfway understand or I could pick up fairly easily with, given my existing level of knowledge and practicing on some personal project. But perhaps the real challenge is in wisely coordinating them all to work on large mission-critial systems?
DarenW
@Daren: The reason i say "beyond advanced" is that at some point your skill set gets to large that you get into different roles and minimally specific skills. For example, performance tuning requires you to know your db engine's internals pretty intimately. Not so for complex query writing. Schema design requires you know be expert in the problem domain you're modelling... etc.
Paul Sasik
I'm not sure stored procedures should be on that list. Things like joins, profiling, schema design, etc are all things that an "advanced" SQL programmer should know and be ready to use, wheras there's still not a consensus on whether stored procedures are "good" or "bad."
ShZ
I'd agree with all but the 1st and 5th points regarding stored procedures. Usually a job posting would explicitly state PL/SQL, stored procedures, or something similar. In large companies those tasks are often relegated to DBAs.
Jess
On our team, at least, if you're a developer then you are expected to develop, whether it's C++ or C# or T-SQL stored procs and schema creation. Advanced SQL for us definitely means more than just writing complex queries -- you really need to know your way around DDL as well as DML.
Joe
@Shz said there's not a consensus on whether stored procedures are "good" or "bad". What the heck? They are neutral, a tool that does something. There are cases to use them and cases not to. Anyone who generalizes to say they are bad is smoking dope...
Emtucifor
+1  A: 

Performance tuning, creating indices, stored procedures, etc.

"Advanced" means something different to everyone. I'd imagine this type of thing means something different to every job-poster.

matt b
Yes, sometimes the poster has no idea what SQL is and thinks advanced SQL is some feature of Microsoft Access they never used. ;-)
harschware
+1  A: 

When you see them spelled out in requirements they tend to include:

  • Views
  • Stored Procedures
  • User Defined Functions
  • Triggers
  • sometimes Cursors

Inner and outer joins are a must but i rarely ever see it mentioned in requirements. And it's surprising how many so-called db professionals cannot get their head around a simple outer join.

Paul Sasik
In my reading, yes, apparently a lot of SW devs dealing with databases don't get joins. Good opportunity for someone to write good education materials on that!
DarenW
+12  A: 

The rest of the job opening listing could provide context to provide a better guess at what "Advanced SQL" may encompass.

I disagree with comments and responses indicating that understanding JOIN and aggregate queries are "advanced" skills; many employers would consider this rather basic, I'm afraid. Here's a rough guess as what "Advanced" can mean.

There's been an "awful" lot of new stuff in the RDBMS domain, in the last few years!

The "Advanced SQL" requirement probably hints at knowledge and possibly proficiency in several of the new concepts such as:

  • CTEs (Common Table Expressions)
  • UDFs (User Defined Functions)
  • Fulltext search extensions/integration
  • performance tuning with new partitionning schemes, filtered indexes, sparse columns...)
  • new data types (ex: GIS/spatial or hierarchical)
  • XML support / integration
  • LINQ
  • and a few more... (BTW the above list is somewhat MSSQL-centric, but similar evolution is observed in most other DBMS platforms).

While keeping abreast of the pro (and cons) of the new features is an important task for any "advanced SQL" practitioner, the old "advanced fundamentals" are probably also considered part of the "advanced":

  • triggers and stored procedures at large
  • Cursors (when to use, how to avoid ...)
  • design expertise: defining tables, what to index, type of indexes
  • performance tuning expertise in general
  • query optimization (reading query plans, knowing what's intrinsically slow etc.)
  • Procedural SQL
  • ...

Note: the above focuses on skills associated with programming/lead role. "Advanced SQL" could also refer to experience with administrative roles (Replication, backups, hardware layout, user management...). Come to think about it, a serious programmer should be somewhat familiar with such practices as well.

Edit: LuckyLindy posted a comment which I found quite insightful. It suggests that "Advanced" may effectively have a different purpose than implying a fair-to-expert level in most of the categories listed above...
I repeat this comment here to give it more visibility.

I think a lot of companies post Advanced SQL because they are tired of getting someone who says "I'm a SQL expert" and has trouble putting together a 3 table outer join. I post similar stuff in job postings and my expectation is simply that a candidate will not need to constantly come to me for help writing SQL. (comment by LuckyLindy)

mjv
LINQ especially seems hot out there, but alas it is not available to those of us in Linuxland. (AFIK)
DarenW
I like this answer for distinguishing different types of "advanced".
DarenW
@DarenW, as indicated this list is somewhat Microsoft-centric. This said LINQ is readily coming to Linux, by way of Mono (I can't speak much to this however, for although I work in both worlds, I don't use Mono when in Unix.
mjv
I think a lot of companies post Advanced SQL because they are tired of getting someone who says "I'm a SQL expert" and has trouble putting together a 3 table outer join. I post similar stuff in job postings and my expectation is simply that a candidate will not need to constantly come to me for help writing SQL.
Jess
@LuckyLindy. Great insight! That's definitively a very plausible use of the "advanced" keyword as well! I liked your comment so much I added it to my text! (with proper credit, of course). Also +1 on your own response, which I just noted...
mjv
+5  A: 

Check out SQL For Smarties. I thought I was pretty good with SQL too, until I read that book... Goes into tons of depth, talks about things I've not seen elsewhere (I.E. difference between 3'rd and 4'th normal form, Boyce Codd Normal Form, etc)...

dicroce
+7  A: 

Basics


  1. SELECTing columns from a table
  2. Aggregates Part 1: COUNT, SUM, MAX/MIN
  3. Aggregates Part 2: DISTINCT, GROUP BY, HAVING

Intermediate


  1. JOINs, ANSI-89 and ANSI-92 syntax
  2. UNION vs UNION ALL
  3. NULL handling: COALESCE & Native NULL handling
  4. Subqueries: IN, EXISTS, and inline views
  5. Subqueries: Correlated
  6. WITH syntax: Subquery Factoring/CTE
  7. Views

Advanced Topics


  • Functions, Stored Procedures, Packages
  • Pivoting data: CASE & PIVOT syntax
  • Hierarchical Queries
  • Cursors: Implicit and Explicit
  • Triggers
  • Dynamic SQL
  • Materialized Views
  • Query Optimization: Indexes
  • Query Optimization: Explain Plans
  • Query Optimization: Profiling
  • Data Modelling: Normal Forms, 1 through 3
  • Data Modelling: Primary & Foreign Keys
  • Data Modelling: Table Constraints
  • Data Modelling: Link/Corrollary Tables
  • Full Text Searching
  • XML
  • Isolation Levels
  • Entity Relationship Diagrams (ERDs), Logical and Physical
  • Transactions: COMMIT, ROLLBACK, Error Handling
OMG Ponies
Great list ... IMO - 99% of companies asking for Advanced SQL skills want are just looking for Intermediate w/ some data modeling.
Jess
Good list. What always surprises me is how often UNION is overlooked by programmers. People often seem to jump though complex hoops trying to assemble multiple table join code when a couple of unions would be far simpler.
Cruachan
@Cruachan: I think that's mostly due to tunnel vision and practice. `UNION`s aren't necessary nearly as often as JOINs.
OMG Ponies
add deeply nested SELECTs.
SF.
SQLMenace
My own list of such a thing would put more of these items into the earlier categories (move advanced to intermediate and intermediate to beginner). I also would probably use the Dreyfus model of skill acquisition and have 5 categories instead of 3. My list would also be much longer and instead of just listing technology features would include conceptual and system-level items. E.g., knowing that seeks are usually better than scans is basic query optimization. Knowing that a design violates useful normal form and exactly how to fix it is intermediate query optimization. ... and so on.
Emtucifor
@SQLMenace: Some of the stuff you'd like to add is very SQL Server-centric - parameter isn't an issue that I'm aware of on any other db, and recovery models is again SQL Server specific.
OMG Ponies
OMG Ponies
A: 

Some "Advanced" features

  • recursive queries
  • windowing/ranking functions
  • pivot and unpivot
  • performance tuning
Scott Weinstein
+2  A: 

I think it's best highlighted with an example. If you feel you could write the following SQL statement quickly with little/no reference material, then I'd guess that you probably meet their Advanced SQL requirement:

DECLARE @date DATETIME
SELECT @date = '10/31/09'

SELECT
      t1.EmpName,
      t1.Region,
      t1.TourStartDate,
      t1.TourEndDate,
      t1.FOrdDate,
      FOrdType  = MAX(CASE WHEN o.OrderDate = t1.FOrdDate THEN o.OrderType  ELSE NULL END),
      FOrdTotal = MAX(CASE WHEN o.OrderDate = t1.FOrdDate THEN o.OrderTotal ELSE NULL END),
      t1.LOrdDate,
      LOrdType  = MAX(CASE WHEN o.OrderDate = t1.LOrdDate THEN o.OrderType  ELSE NULL END),
      LOrdTotal = MAX(CASE WHEN o.OrderDate = t1.LOrdDate THEN o.OrderTotal ELSE NULL END)
  FROM 
      (--Derived table t1 returns the tourdates, and the order dates
      SELECT
            e.EmpId,
            e.EmpName,
            et.Region,
            et.TourStartDate,
            et.TourEndDate,
            FOrdDate = MIN(o.OrderDate),
            LOrdDate = MAX(o.OrderDate)
        FROM #Employees e INNER JOIN #EmpTours et
          ON e.EmpId = et.EmpId INNER JOIN #Orders o
          ON e.EmpId = o.EmpId
       WHERE et.TourStartDate <= @date
         AND (et.TourEndDate > = @date OR et.TourEndDate IS NULL)
         AND o.OrderDate BETWEEN et.TourStartDate AND @date
       GROUP BY e.EmpId,e.EmpName,et.Region,et.TourStartDate,et.TourEndDate
      ) t1 INNER JOIN #Orders o
    ON t1.EmpId = o.EmpId
   AND (t1.FOrdDate = o.OrderDate OR t1.LOrdDate = o.OrderDate)
 GROUP BY t1.EmpName,t1.Region,t1.TourStartDate,t1.TourEndDate,t1.FOrdDate,t1.LOrdDate

(source of query)

And to be honest, that's a relatively simple query - just some inner joins and a subquery, along with a few common keywords (max, min, case).

Jess
Nothing like a real life example to gawk at. I think I could write stuff like that, but only with much trial and error and looking up details.
DarenW
Criticisms/comments for your query: 1. db design: TourEndDate column should use something like 12/31/9999 for the "no end date" value instead of NULL because of performance implications of having to add "OR TourEndDate IS NULL". This OR will likely get scans instead of seeks. 2. Your query assumes that there can't be more than one Order per Employee per OrderDate. Is that enforced in the db? 3. Can EmpTours overlap? If so, there are db design problems. 4. Why can't an OrderDate be before the TourStartDate? 5. Employees table should be outside derived table. 6. More thoughts but no room...
Emtucifor
A: 

At my previous job, we had a technical test which all candidates were asked to sit. 10ish questions, took about an hour. In all honesty though, 90% of failures could be screened out because they couldn't write an INNER JOIN statement. Not even an outer.

I'd consider that a prerequisite for any job description involving SQL and would leave well alone until that was mastered. From there though, talk to them - any further info on what they're actually looking for will, worst case scenario, be a useful list of things to learn as part of your professional development.

eftpotrm
A: 

"Advanced SQL" is a contradiction of terms.

Erwin Smout
Your humor didn't quite come through. You'll have to do better to adequately convey sarcasm or irony in your statement so people will understand your true meaning that SQL is in fact quite difficult and complicated and "beginning SQL" is the real contradiction in terms you were pointing out.
Emtucifor