The beauty of SQL *updated with code*

Mucman

Diamond Member
Oct 10, 1999
7,246
1
0
Have any of you written some SQL statements that were so beautiful and elegant that you wanted to print them out
on a piece of paper and hang them in your office?

I know that I got some... there's something attractive about well written and efficient T-SQL.
 

tweakmm

Lifer
May 28, 2001
18,436
4
0
The only way you could be more of a nerd is if you printed them off and wacked to them:p
 

Drakkon

Diamond Member
Aug 14, 2001
8,401
1
0
regular expressesions > [a-z]*
although I actually know a guy who did the SQL thing (posting them around his cubicle you sickos)...but it was with good reason to remeber how the heck to index stuff and reindex stuff :p
 

AgaBoogaBoo

Lifer
Feb 16, 2003
26,108
5
81
Originally posted by: tweakmm
The only way you could be more of a nerd is if you printed them off and wacked to them:p

So thats why you printed out 50 copies for every room and bathroom you visit in a day.... ah, I see. Very smart!

:beer::D:brokenheart::camera::clock::confused::cool::disgust::eek::evil::frown::gift::heart::light::lips::|:moon::music:
rolleye.gif
rose.gif
:(:Q:):sun::p:wine:;)
 

Mucman

Diamond Member
Oct 10, 1999
7,246
1
0
Originally posted by: joshsquall
Once you start asking your lady friends to outer left join you in bed, I will be scared.

umm... wouldn't you want to do an INNER JOIN for that? the OUTER JOIN can result in some NULL results leaving you with you and your
manhood alone.

 

cyclistca

Platinum Member
Dec 5, 2000
2,885
11
81
Mucman you need a woman in your life. ;) I've written some pretty cool SQL that I can say I very proud of. However I'm not about to
start hanging it in my office.
 

Descartes

Lifer
Oct 10, 1999
13,968
2
0
Show us your idea of a beautiful TSQL statement :) I'm certain beauty is in the eye of the beholder in this case ;)

I'm usually prouder of my regular expressions or code than TSQL statements.
 

Mucman

Diamond Member
Oct 10, 1999
7,246
1
0
Here are some examples.

I'm sure it's childs play to you guys you have been doing this for a quarter of a century, but
since I just learned what SQL was a year ago, I'm happy with my progress :) So go easy
on me if this isn't complex enough to hang on the wall :p

I remember some of my first queries though... they were hurtin! Lots of needless sub-queries
and ended up doing stuff on the scripting side since I didn't know some things were possible
in SQL.

Just today I learned a handy device... I am writing an app to create playlists for my radio, and I
want to randomly fetch songs from the database.

SELECT S.songid, S.title FROM songs S ORDER BY RAND() LIMIT 50

How simple is that?
 

Hector13

Golden Member
Apr 4, 2000
1,694
0
0
Originally posted by: Mucman
Just today I learned a handy device... I am writing an app to create playlists for my radio, and I
want to randomly fetch songs from the database.

SELECT S.songid, S.title FROM songs S ORDER BY RAND() LIMIT 50

How simple is that?

simple, maybe, but neither RAND() or LIMIT are part of standard SQL (at least not sql 89, which is the lates widely supported version, I think)
 

Blum81

Junior Member
Jul 1, 2003
2
0
0
Originally posted by: cyclistca
Mucman you need a woman in your life. ;) I've written some pretty cool SQL that I can say I very proud of. However I'm not about to
start hanging it in my office.

he has a poster of David Usher in his office
 

Mucman

Diamond Member
Oct 10, 1999
7,246
1
0
blum81, it's Pete Yorn! and before people starting thinking I'm ***, I also have a poster of the White Stripes, and The New Pornographers on there! :D

Hector13, Those functions were used in mysql 3.whatever. I should check if they work with firebird RDBMS because I may try migrating to that.

btw, I see someone is listening to Muc-Radio! Enjoying it? :)
 

KeyserSoze

Diamond Member
Oct 11, 2000
6,048
1
81
That is cool. I guess all we need now is a username, passoword, and a "connect string", and we'll be on our way. :p






KeyserSoze
 

Mucman

Diamond Member
Oct 10, 1999
7,246
1
0
Originally posted by: KeyserSoze
That is cool. I guess all we need now is a username, passoword, and a "connect string", and we'll be on our way. :p

KeyserSoze

If you had that information, whatever I posted would be irrelevent because you would simply connect to the
database and look at the schema yourself :). All these scripts are internally run, so SQL Injection hacks aren't
go to happen unless you work with me :p

Heck, my server is public on the Internet! All you need is my root password and you can h4x0r m3! Actually, I
disable remote root logins but still... :p