0

My sql string is like:

SELECT t.*
FROM table AS t
GROUP BY t.month

the result like:

ID  data month
1     0    1
2     1    2
3     2    4
4     3    5

I need select in ,for example,the first five month,so I need right outer join another table, the table is like this:

month
 1
 2
 3
 4
 5

It's not a real table in database, my expecting result is like:

 ID  data month
 1     0    1
 2     1    2
            3
 3     2    4
 4     3    5

how do I write this query?

user1021531
  • 487
  • 1
  • 7
  • 16
  • What is the structure of both tables? – Adam Wenger Dec 05 '11 at 03:49
  • post your table schema and possible some data and desired result – rahularyansharma Dec 05 '11 at 03:52
  • This question is unclear, vague, and can't possibly be answered. Please rephrase with additional information about what you're trying to do. What is the structure of your database (and a few row samples might not hurt either)? What is your expected result? – RonLugge Dec 05 '11 at 03:53
  • possible duplicate of [Display values that is table2 but not in table1](http://stackoverflow.com/questions/7897722/display-values-that-is-table2-but-not-in-table1) – Phil Dec 05 '11 at 03:54

2 Answers2

0
SELECT t.month
FROM table AS t
GROUP BY t.month
UNION SELECT FOO;

Replace FOO with the value you want to append.

kba
  • 19,333
  • 5
  • 62
  • 89
Andrew Kolesnikov
  • 1,920
  • 1
  • 14
  • 20
0

I'm not clear what you mean by join. But this is the solution to one of the possible interpretations (return only those rows not contained in the other table)

SELECT ....
FROM table AS t
WHERE t.month not in (
    SELECT id 
    FROM month
)
GROUP BY t.month
Jens Schauder
  • 77,657
  • 34
  • 181
  • 348