1

I have records in few rows, but need to get them all into one with query.

Here it is:

http://img341.imageshack.us/img341/7808/captn.png

LARGE IMAGE LINK

1
  • @Strawberry +1 on normalization... Commented Jan 12, 2013 at 15:41

3 Answers 3

4
SELECT  MAX(rbr) maxRBR,
        id, date,
        MAX(pr1) maxPr1,
        MAX(pr2) maxPr2,
        ....
FROM tableName
GROUP BY id, date
Sign up to request clarification or add additional context in comments.

4 Comments

This will select max value for that column, what if I have 2 or more and in same column, and I need last one?
max will return one value which is the highest among the group, try it.
I don't need max, I need last ( highest with rbr)
Yeah, if you need to be more specific about which of the multiple values you want to select, you'll have to be more specific about exactly how you'd choose that value. Max dat field? Last inserted? We'd need a more detailed example.
2
SELECT id, dat, MAX(pr1) pr1, MAX(pr2) pr2, ...
FROM table
GROUP BY id, dat

Comments

2

For each field which you want to coalesce non-null values you can use this:

SELECT 
    id, 
    date,
    COALESCE(field1),
    COALESCE(field2)
FROM 
    table
GROUP BY 
    id

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.