Click here to Skip to main content
15,896,063 members
Home / Discussions / Database
   

Database

 
AnswerRe: Multiple Join to the same field Pin
David Mujica29-May-13 4:56
David Mujica29-May-13 4:56 
AnswerRe: Multiple Join to the same field Pin
Mycroft Holmes29-May-13 12:49
professionalMycroft Holmes29-May-13 12:49 
QuestionSelect top 2 not working on Maximum Record using SQL Pin
SE Ubaid29-May-13 2:38
SE Ubaid29-May-13 2:38 
AnswerRe: Select top 2 not working on Maximum Record using SQL Pin
Eddy Vluggen29-May-13 3:17
professionalEddy Vluggen29-May-13 3:17 
AnswerRe: Select top 2 not working on Maximum Record using SQL Pin
Arman S.29-May-13 9:44
Arman S.29-May-13 9:44 
Questiondecryption Pin
Member 870181328-May-13 6:42
Member 870181328-May-13 6:42 
AnswerRe: decryption Pin
R. Giskard Reventlov28-May-13 7:43
R. Giskard Reventlov28-May-13 7:43 
QuestionRe: decryption Pin
Eddy Vluggen28-May-13 9:45
professionalEddy Vluggen28-May-13 9:45 
AnswerRe: decryption Pin
Member 870181330-May-13 16:37
Member 870181330-May-13 16:37 
GeneralRe: decryption Pin
Eddy Vluggen31-May-13 6:23
professionalEddy Vluggen31-May-13 6:23 
AnswerRe: decryption Pin
poongunrans28-May-13 20:21
poongunrans28-May-13 20:21 
QuestionSQL Pin
Shiv irfi26-May-13 21:11
Shiv irfi26-May-13 21:11 
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 
Here's a problem I've come up against on a number of occasions and I have so far failed to come up with an elegant query to deal with it. I feel the GROUP BY clause might have to come into play but I don't really know how.

Let's say I have a table called Orders containing information on orders received from customers. The table has the following columns:
CustomerID (INT)<br />
OrderPlaced (DATETIME)<br />
ProductID (INT)<br />
AmountOrdered (INT)


So I want to write a query that will show me the information from this table on the first order for a specific product (let's say id 123) received by every customer.

The following query will get me almost there:

SQL
SELECT CustomerID, MIN(OrderPlaced)
FROM Orders
WHERE ProductID = 123


It only gets me almost there though because notice how the AmountOrdered field is missing from the query and unless it's part of an aggregate function I can't add it. I can add it with a subquery but that is where the query loses its elegance rapidly, especially considering that the real world tables I'm dealing with usually have more than just one or two extra columns.

Any ideas?
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 
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 

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.