Click here to Skip to main content
15,887,596 members
Home / Discussions / Database
   

Database

 
AnswerRe: SQL Pin
Mycroft Holmes26-May-13 21:52
professionalMycroft Holmes26-May-13 21:52 
JokeRe: SQL Pin
Killzone DeathMan28-May-13 5:35
Killzone DeathMan28-May-13 5:35 
AnswerRe: SQL Pin
Eddy Vluggen28-May-13 9:59
professionalEddy Vluggen28-May-13 9:59 
AnswerRe: SQL Pin
Azarudhin4-Jun-13 3:45
professionalAzarudhin4-Jun-13 3:45 
AnswerRe: SQL Pin
prakash.chakrala5-Jul-13 1:09
prakash.chakrala5-Jul-13 1:09 
QuestionSelect first entries in a table matching given criteria Pin
Dewald26-May-13 10:12
Dewald26-May-13 10:12 
AnswerRe: Select first entries in a table matching given criteria Pin
Mycroft Holmes26-May-13 12:47
professionalMycroft Holmes26-May-13 12:47 
GeneralRe: Select first entries in a table matching given criteria Pin
Dewald26-May-13 22:10
Dewald26-May-13 22:10 
Thanks. I've been shying away from Over(), ROW_NUMBER and Partition By because they're rather Microsoft specific.

I agree, generally there's nothing inelegant about using a subquery but in this particular case it is anything but elegant.

Consider the table in my example and let's say there are a few more columns:
ContractID (INT)<br />
OrderSource (INT)<br />
AgentID (INT)<br />
ProvinceID (INT)<br />
DeliveryMethod (INT)


So, in order to get what I want, using GROUP BY and subqueries, it would end up looking something like this:

SQL
SELECT
    CustomerID,
    MIN(OrderPlaced),
    --(Some or other subquery to get the value for AmountOrdered),
    --(Some or other subquery to get the value for ContractID),
    --(Some or other subquery to get the value for OrderSource),
    --(Some or other subquery to get the value for AgentID),
    --(Some or other subquery to get the value for ProvinceID),
    --(Some or other subquery to get the value for DeliveryMethod)
FROM Orders
WHERE ProductID = 123
GROUP BY CustomerID


I'm sure you'll agree that the above query is pretty much the antithesis of elegance.

modified 27-May-13 4:18am.

GeneralRe: Select first entries in a table matching given criteria Pin
Mycroft Holmes26-May-13 22:35
professionalMycroft Holmes26-May-13 22:35 
GeneralRe: Select first entries in a table matching given criteria Pin
Dewald26-May-13 22:56
Dewald26-May-13 22:56 
GeneralRe: Select first entries in a table matching given criteria Pin
Mycroft Holmes26-May-13 23:04
professionalMycroft Holmes26-May-13 23:04 
GeneralRe: Select first entries in a table matching given criteria Pin
Jörgen Andersson27-May-13 0:32
professionalJörgen Andersson27-May-13 0:32 
GeneralRe: Select first entries in a table matching given criteria Pin
Dewald27-May-13 0:54
Dewald27-May-13 0:54 
GeneralRe: Select first entries in a table matching given criteria Pin
Jörgen Andersson27-May-13 11:12
professionalJörgen Andersson27-May-13 11:12 
QuestionWindows accounts for SSE Pin
Richard.Berry10025-May-13 22:35
Richard.Berry10025-May-13 22:35 
QuestionVA Database Pin
Daaron24-May-13 4:10
Daaron24-May-13 4:10 
QuestionRe: VA Database Pin
Eddy Vluggen24-May-13 4:18
professionalEddy Vluggen24-May-13 4:18 
AnswerRe: VA Database Pin
jschell24-May-13 12:40
jschell24-May-13 12:40 
AnswerRe: VA Database Pin
Richard MacCutchan24-May-13 4:19
mveRichard MacCutchan24-May-13 4:19 
AnswerRe: VA Database Pin
R. Giskard Reventlov24-May-13 5:15
R. Giskard Reventlov24-May-13 5:15 
GeneralRe: VA Database Pin
PIEBALDconsult24-May-13 11:45
mvePIEBALDconsult24-May-13 11:45 
AnswerRe: VA Database Pin
jschell24-May-13 12:43
jschell24-May-13 12:43 
QuestionCreate Mysql Music Database Help Pin
Muveen_Delhi23-May-13 22:28
Muveen_Delhi23-May-13 22:28 
AnswerRe: Create Mysql Music Database Help Pin
Eddy Vluggen24-May-13 3:02
professionalEddy Vluggen24-May-13 3:02 
GeneralRe: Create Mysql Music Database Help Pin
Muveen_Delhi24-May-13 18:08
Muveen_Delhi24-May-13 18:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.