Torin/Darren WhoEver (wolfieboy) wrote,
Torin/Darren WhoEver
wolfieboy

  • Mood:
  • Music:

Scary SQL (at least to me)

It rather scares me that I'm now able to write SQL like the following:
SELECT c.bac FROM transmission_log tl0, cars c
WHERE (tl0.creation_date, tl0.cars_id) IN ( SELECT MAX(tl1.creation_date), tl1.cars_id FROM transmission_log tl1 GROUP BY tl1.cars_id )
AND tl0.status = 'Pending' AND c.cars_id = tl0.cars_id
What this says is the grab the bac (Business Associate Code) from the cars table if the newest corresponding record in the transmission_log table has a status of 'Pending'.

And to think that when I started here, I was still getting comfortable with two/three table joins. In the great scheme of things, this probably isn't complex SQL but it's pretty complex for me.
Subscribe
  • Post a new comment

    Error

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.
  • 52 comments