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 |
|
paultervit
Starting Member
10 Posts |
Posted - 2009-01-14 : 11:39:50
|
| HelloI am having a problem with a sql query I am trying to write. I have two tables e.g.Table 1User1234Table 2Login Name12:30 112:45 212:46 113:15 3I would like to return the followingName Login Count1 22 13 14 0My query so far uses a join and a count but only returns the rows with entrys in both tables. Is there an easy way to get the return I am looking for?P.s. my current query is as followsSELECT 1.User, COUNT(2.Login) Cnt FROM table1 1 join table2 2 on 1.name = 2.nameGROUP BY 1.nameORDER BY Cnt DESCThanksPaul |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-01-14 : 11:52:41
|
use left joinSELECT 1.User, COUNT(2.Login) Cnt FROM table1 1 left join table2 2 on 1.name = 2.nameGROUP BY 1.nameORDER BY Cnt DESC |
 |
|
|
|
|
|