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 |
marek
Starting Member
34 Posts |
Posted - 2009-06-13 : 18:31:25
|
HalloI need help, please. I want join 2 tables (TabCompany and TabSalesman)For example:TabCompanyid/Company1/dell2/canon3/bros4/hitachiTabSalesmanid/salesman1/mark1/mark2/alf2/bob2/cruis2/alf3/smith3/cruiseresults:id/company/salesman1/dell/mark2/canon/alfbobcruise--->or: alf,bob,cruise3/bros/smith,cruise4/hitachithanks for syntax this specific(concrete) problem. |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-06-14 : 01:41:00
|
[code]SELECT c.id,c.Company,s1.salesmanFROM TabCompany cINNER JOIN (SELECT DISTINCT id,STUFF((SELECT DISTINCT ',' + salesman FROM TabSalesman WHERE id=s.id FOR XML PATH('')),1,1,'') AS salesmanFROM TabSalesman s)s1ON s1.id=c.id[/code] |
|
|
marek
Starting Member
34 Posts |
Posted - 2009-06-14 : 04:51:49
|
thanks Visakh16 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-06-14 : 04:59:19
|
welcome |
|
|
abacusdotcom
Posting Yak Master
133 Posts |
Posted - 2009-06-15 : 13:00:05
|
hi,My case here is I have a table having my records say table with this structure Table Aid/date/amount1/200901/502/200905/4001/200906/20Table BID/date/days1/200901/22/200901/51/200912/231/200809/5How can I get the occurrence records in Table A from Table B base on Id and date?I sign for fame not for shame but all the same, I sign my name. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-06-15 : 13:50:18
|
do you mean this?SELECT a.id,a.date,a.amount,count(b.id)FROM TableA aLEFT JOIN TableB bON a.id=b.idAND a.date=b.dateGROUP BY a.id,a.date,a.amount |
|
|
|
|
|
|
|