LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-12-2005, 10:42 AM   #1
jpc82
Member
 
Registered: Oct 2001
Distribution: Gentoo
Posts: 140

Rep: Reputation: 15
SQL question


I have a query I am trying to do in SQL, but I don't know how to do it.

I have 4 tables (T1, T2, T3, T4) and I need to link them all togethr and get the max of a couple of fields.

Here basic descirption of what I need to do
T1 has the name of the data
T2 is used to link T1 to T3
T3 has 2 sets of dates, I need the min of one and the max of the other
T4 has a status, which is either 'RED', 'Green', 'Yellow'

Now I have T1, T2, and T3 linking properly so the min and max of the dates is getting displayed.

Sample output

Data MaxDate MinDate
D1 1/1/2007 1/1/2003

Now I need help linking T1 to T4 and having it pull the colour that I need. If any record has red I want red to show up, if any record has Yellow and not red then yellow is shown, if only green is there I want green to show up, and if no records I want it to be blank.
 
Old 08-12-2005, 11:03 AM   #2
jpc82
Member
 
Registered: Oct 2001
Distribution: Gentoo
Posts: 140

Original Poster
Rep: Reputation: 15
Actual I was just think that as long as I can get the right color being selected I can just join it to my other search.

So does any one know how to get the colours to get selected with this priority (Red - Yellow - Green). If I just do max Yellow gets a higher priority then Red, and with min Green gets the highest priority.

Thanks for any help.
 
Old 08-13-2005, 08:27 AM   #3
eddiebaby1023
Member
 
Registered: May 2005
Posts: 378

Rep: Reputation: 33
I can't do blank paper SQL - post what you've used so far and I'll see if I can add the necessary bits.
 
Old 08-13-2005, 09:03 AM   #4
jpc82
Member
 
Registered: Oct 2001
Distribution: Gentoo
Posts: 140

Original Poster
Rep: Reputation: 15
Ok this is basically what I have

SELECT T_Release.name, MAX(Status.Colour) AS Colour FROM T_Release INNER JOIN T_Project ON T_Release.id = T_Project.ReleaseID INNER JOIN Status ON T_Project.id = Status.ProjectID GROUP BY T_Release.name


My problem is the fact that SQL does orders with strings alphabetically, which I don't what. I want this order
Red
Yellow
Green
NULL

I don't know how to do that.
 
Old 08-13-2005, 10:57 AM   #5
oblivious69
Member
 
Registered: May 2005
Distribution: debian
Posts: 79

Rep: Reputation: 15
Maybe set up another table with colors and the order you want them printed by and use the ORDER BY clause.
 
Old 08-13-2005, 11:05 AM   #6
jpc82
Member
 
Registered: Oct 2001
Distribution: Gentoo
Posts: 140

Original Poster
Rep: Reputation: 15
actually that makes sence, I never thought of that thanks
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
sql plus question puishor Linux - Software 3 10-23-2005 02:09 PM
sql disconnect question jacksmash Programming 5 08-06-2005 11:46 PM
SQL Question jacksmash Programming 7 01-18-2004 10:10 PM
(postgre) SQL question J_Szucs Programming 4 09-18-2003 08:40 PM
SQL and searching question Robert0380 Programming 3 08-18-2002 11:34 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:15 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration