# Thread: Problem with GROUP BY

1. ## Problem with GROUP BY

Hi all.

I have problem with this table:

Code:
```DATE		METEO
2008-11-05	1
2008-11-05	2
2008-10-29	1
2008-10-29	1
2008-10-29	1
2008-10-29	1```
My query:

Code:
```SELECT
METEO, `DATE`
FROM
TBL
WHERE
`DATE` = '2008-10-09'
GROUP BY
METEO```
I need this:

1
1

If I have delete in the query

Code:
```   GROUP BY
METEO```
I have:

1
1
1
1

Can you help me?
kid regards
Viki

2. let's start at the beginning... why are you using GROUP BY and what are you hoping it will do for you?

notice also that the WHERE clause you gave would return no rows from the sample you gave

you have to be very careful about small details when working with computers, eh

3. OK, I'am sorry the query is:

Code:
```SELECT
METEO, `DATE`
FROM
TBL
WHERE
`DATE` = '2008-10-29'
GROUP BY
METEO```
I use the clause GROUP BY because I need when `DATE` = '2008-10-29' see only :

1
1

and I see when `DATE` = '2008-11-05' only:

1
2

4. remove `DATE` from the SELECT clause

can you explain why there would be two rows returned for '2008-10-29'

there should be only one

5. OK.

My problem this is:

I extract with query for DATE only two first rows:

Code:
```DATE		METEO
2008-11-05	1
2008-11-05	2
2008-10-29	1
2008-10-29	1
2008-10-29	1
2008-10-29	1```
when `DATE` = '2008-10-29' I see :

1
1

when `DATE` = '2008-11-05' I see :

1
2

6. what is the datatype of the `DATE` column?

can you explain why there would be two rows returned for '2008-10-29'

7. datatype of the `DATE` column is DATE.

8. then the only conclusion i can reach is that you're not showing us the exact query

because you would get only one row for '2008-10-29'

9. I need when query extract only one row double the same value:

when `DATE` = '2008-10-29' only one row, I see :

1
1

It's not possible...

10. viki, i realize that english is probably not your native language, but you aren't making any sense

please give me a CREATE TABLE statement, as well as several INSERT statements, to create a sample table so that it will demonstrate your problem

i'm not even sure i understand what you're asking

11. Iam sorry for my english, but is not easy...

In this case:

Code:
```DATE		METEO
2008-11-05	1
2008-11-05	2
2008-10-29	1
2008-10-29	1
2008-10-29	1
2008-10-29	1```
The query:

Code:
```SELECT
METEO, `DATE`
FROM
TBL
WHERE
`DATE` = '2008-10-29'
GROUP BY
METEO```
extract this row:

Code:
`2008-10-29	1`
Because I use the clause GROUP BY METEO in the query.

In this case, would only one row, I need see :

Code:
```2008-10-29	1
2008-10-29	1```
Mean doubling the row extracted...

12. oh, i think i understand now, you want doubled output

(i don't understand why, but that's a different question, i guess)

here, try this --
Code:
```SELECT METEO
FROM TBL
WHERE `DATE` = '2008-10-29'
GROUP
BY METEO
UNION ALL
SELECT METEO
FROM TBL
WHERE `DATE` = '2008-10-29'
GROUP
BY METEO```

13. Originally Posted by r937
(i don't understand why, but that's a different question, i guess)
Because in the table I have this situation:

Code:
```DATE		METEO		TURN
2008-11-05	1		OFF
2008-11-05	2		ON
2008-10-29	1		OFF
2008-10-29	1		OFF
2008-10-29	1		OFF
2008-10-29	1		OFF```
Your last query working but in this case:

Code:
```DATE		METEO
2008-11-05	1
2008-11-05	2```
I see:

1
2
1
2

Why?

14. because you wanted the output doubled

15. Originally Posted by r937
because you wanted the output doubled
Only in ths case:

Code:
`2008-10-29	1`

16. the camel has finally pushed me out of the tent

17. Originally Posted by r937
the camel has finally pushed me out of the tent
what?

18. Originally Posted by viki1967
what?
http://en.wikipedia.org/wiki/Camel's_nose

it means i am not going to continue on this problem

sorry

19. Originally Posted by r937
http://en.wikipedia.org/wiki/Camel's_nose

it means i am not going to continue on this problem

sorry
why not propose an alternative solution to my problem ?

20. likely because you didn't answer his questions and then you complained when it didn't work. and you told him what you 'wnated' only to come back later to say you wanted something else. people are busy and are doing this voluntarily. So it is important and the onus is on us as questioners, to give the full picture.

bazz

21. Originally Posted by IBazz
likely because you didn't answer his questions and then you complained when it didn't work. and you told him what you 'wnated' only to come back later to say you wanted something else. people are busy and are doing this voluntarily. So it is important and the onus is on us as questioners, to give the full picture.

bazz
I not have intention to offend and complain r937...
I'am problem with english... is not my native language...
if offend I'am sorry...

22. yes, viki, i understand, and please do not worry, you did not offend me at all

23. thanks...

I resolved my problem whit server language and two queries ...

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•