Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- select *,
- (select count(*) from tbl2 t2 where t2.tbl1ID = t1.tbl1ID) as cnt
- from tbl1 t1
- declare @tbl1 table
- (
- tbl1ID int,
- prop1 varchar(1),
- prop2 varchar(2)
- )
- declare @tbl2 table
- (
- tbl2ID int,
- tbl1ID int
- )
- select *,
- (select count(*) from @tbl2 t2 where t2.tbl1ID = t1.tbl1ID) as cnt
- from @tbl1 t1
- select t1.ID, t1.property1, t1.property2, t2.somecol, t2.someothercol
- from table t1 left join anothertable t2 on t1.ID = t2.ID
Add Comment
Please, Sign In to add comment