LiveWire Network Peer Answers Peer Support Teen Forums Tech Forums College Forums 520 users online 225200 members 1051 active today Advertise Here Sign In
TeenCollegeTechPhotos | Quizzes | LiveSecret | Memberlist | Dictionary | News | FAQ
Member Spotlight
agerask
Peeves: Loud breathers, leg tappers, and liars...
Mood: Plain
You have 1 new message.
Emergency Help
Until you sign up you can't do much. Yes, it's free.

Sign Up Now
Membername:
Password:
Already have an account?
Invite Friends
Active Members
Groups
Contests
Moderators
5 online / 24 MPM
Christmas Eve
Fresh Topics
  LiveWire / Technical Forums / Programming & Application Development / Adding Reply

Adding Reply
Topic The power of SQL
Membername   Not a member? Sign Up Free (takes 20 seconds)
Password   Forgotten your password?
Post

Font:   Size:   Color:

FAQ Keyword Search:
Post Options
Favorites Manager
Notify me of new replies to this topic by email
Notify me of new replies to this topic by private message
Original Post
pleaseremove Posted at 6:28 am on May 29, 2009
OK, I was going to post a question, but given I have solved it there is little need. What however I thought I would post was a quick snippet to show people how powerful even a basic engine like MySQL really is.

Code:

SELECT CONCAT('http://someurl/', reviews.id) AS link,  
filmdb.Film AS title,
DATE_FORMAT(STR_TO_DATE(CONCAT(reviews.day, ',', reviews.month, ',', reviews.year), '%d,%m,%Y'), '%a, %d %b %Y %H:%i:%S +0000') AS date,
CONCAT(reviews.writ, ' reviews ', filmdb.Film) AS description
FROM reviews
JOIN filmdb ON filmdb.id = reviews.id
ORDER BY `reviews`.`id` DESC
LIMIT 0 , 15

Here this is generating each of the items needed for an RSS feed. In this case, because of old poor design of the database the date is stored in 3 fields, day, month and year. This code actually converts them into a correctly formatted datetime for RSS.

People forget you can do casting, string manipulation and conversions etc all in SQL. it makes for often much nicer and faster systems if you get it right.

After all, SQL as it exists in MSSQL and DB2 etc are Turing complete and fully featured programming languages.

Replies
JamesBrauman Posted at 6:11 pm on June 17, 2009
Yeah SQL is great, but kind of confusing if you've never done it before (as opposed to procedural languages).
Spiker19 Posted at 7:49 am on June 10, 2009
I hate SQL, solely because the tutor who taught us it in university was completely useless and didnt exactly TEACH us it. They simply gave us a big long confusing coursework to do and we basically had to learn the SQL and Coldfusion code ourselves. Something went wrong with my SQL where it just output every record over and over and he didnt even help fix it. Just told me what it was called. Pfft
matto Posted at 2:25 pm on May 30, 2009
SQL has been very interesting and useful in my limited use of it.  Cool example!
Sector Corrupt Posted at 6:46 pm on May 29, 2009
Yeah, they're fully featured, It's just more difficult to get the hang of them. Most people don't get into doing databases until they've already got a fair amount of programming experience, and It's a completely different paradigm from what people are used to. Declarative is trickier, or at least looks it to me. I've yet to use SQL though I'll probably be adding a Database to one of my programs so I'll need it then.
All 4 previous replies displayed.