Post a long SQL-query!

Stuff that don´t fit in the other categories.
Post Reply
User avatar
ayu
Staff
Staff
Posts: 8109
Joined: 27 Aug 2005, 16:00
18
Contact:

Post a long SQL-query!

Post by ayu »

Post a long SQL-query that you made.
Doesn't have to be the longest you can find.

This is one I am working with at the moment, the size varies depending on some parameters, but this is basically it.

It's for a tool that I am developing for a course at Uni.
It's supposed to help exam planers with their work.
This SQL-query in particular, is used to detect exam collisions.

Code: Select all

SELECT 
Programs.ProgramName, 
Courses.CourseCode, 
Courses.CourseType 
FROM Programs 
INNER JOIN CPConnection ON ProgramID = CProgramID
INNER JOIN Courses ON CCourseID = CourseID 
INNER JOIN Statuses ON Courses.StatusID = Statuses.StatusID 
WHERE 
(Courses.ExamDate = '2009-11-19' 
OR Courses.ReExamDate1 = '2009-11-19' 
OR Courses.ReExamDate2 = '2009-11-19') 
AND NOT (Courses.ExamDate = '0000-00-00' 
OR Courses.ReExamDate1 = '0000-00-00' 
OR Courses.ReExamDate2 = '0000-00-00') 
AND NOT Courses.CourseID = 50 
AND (Statuses.StatusName = 'Bokad' 
OR Statuses.StatusName = 'Planerad') 
AND Programs.ProgramName = 'FriAPS';
"The best place to hide a tree, is in a forest"

User avatar
ayu
Staff
Staff
Posts: 8109
Joined: 27 Aug 2005, 16:00
18
Contact:

Post by ayu »

aww come on boys and girls, don't be shy ; - )
"The best place to hide a tree, is in a forest"

User avatar
bad_brain
Site Owner
Site Owner
Posts: 11636
Joined: 06 Apr 2005, 16:00
19
Location: In your eye floaters.
Contact:

Post by bad_brain »

um, I would have a few, but I don't want to give away info about the suck-o database... :lol:
but on my customer server I will have to log the sql queries anyway because I want to optimize them (some don't use indexes), I'm sure I'll have some nice ones coming up...^^
Image

User avatar
ayu
Staff
Staff
Posts: 8109
Joined: 27 Aug 2005, 16:00
18
Contact:

Post by ayu »

Lovely ^^


I love the smell of fresh queries in the morning ...
"The best place to hide a tree, is in a forest"

User avatar
Gogeta70
^_^
^_^
Posts: 3275
Joined: 25 Jun 2005, 16:00
18

Post by Gogeta70 »

Well, my query doesn't come even close to being as long as yours is cats, but this is from the forum system i've been developing:

Code: Select all

INSERT INTO 
topics 
(fid, tid, priority, tname, tdesc, lposter, lpost_date, author, access_level) 
VALUES 
('$f id', '$ tid', '0', '$ title', '$d esc', '". $_SE SSION['username'] ."', '". time() ."', '". $_SE SSION['username'] ."', '$al vl')"
PS: Dammit b_b, i had to put spaces in the variables just to post >_< XD
¯\_(ツ)_/¯ It works on my machine...

Post Reply