Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
Jarhead104
Starting Member
10 Posts |
Posted - 2010-01-18 : 09:20:48
|
| Hey!Table A:id username1 bla2 blo3 blubTable B:id users_id date1 1 20092 1 20103 1 20114 2 20095 3 20066 3 20077 3 20088 3 20099 3 201010 3 2010I now want to select id, username of table A and ONLY ONE value of date of table B. Result should be:id username date1 bla 20092 blo 20093 blub 2006What I have:Select a.id, a.username, b.date from a inner join b on a.id = b.users_idBut when i add a group by a.id argument i get an exception.It says that b.date is not part of the group by argument and that this does not work...but i do not want to group by b.date...Best regards,Thomas |
|
|
Kristen
Test
22859 Posts |
Posted - 2010-01-18 : 09:31:07
|
| "ONLY ONE value of date of table B"How did you decide WHICH value from table B you would display? Is it the MINimum value?? |
 |
|
|
Jarhead104
Starting Member
10 Posts |
Posted - 2010-01-18 : 09:57:07
|
| Yeah, the minimum value or the first value...actually that's not so important due the fact that "date" is actually a time and the differences between the times are only some milliseconds and are not important for this query.So i dont care which value...im fine with the easiest one ;) |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2010-01-18 : 10:23:07
|
| [code]Select a.id, a.username, MIN(b.date)from a inner join b on a.id = b.users_idGROUP BY a.id, a.username[/code] |
 |
|
|
Jarhead104
Starting Member
10 Posts |
Posted - 2010-01-18 : 10:55:47
|
| Works great!Thank you, Kristen! |
 |
|
|
|
|
|