| Author |
Topic |
|
oguzkaygun
Yak Posting Veteran
53 Posts |
Posted - 2011-10-08 : 10:53:31
|
| HelloI have two tables like below.Table 1ID NAME TABLE2ID1 Apple 1Table 2ID NAME NAMEID1 Yellow 11 Yellow 2I want Grid display like belowApple Yellow. Only one record.if there second apple as name at Table 1 like belowID NAME TABLE2ID1 Apple 12 Apple 1Grid should be display like below.Apple YellowApple Yellow. How can i do this ?Thank you. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-10-08 : 11:10:38
|
| [code]SELECT t1.NAME,t2.NAMEFROM Table1 t1JOIN Table2 t2ON t2.ID = t1.TABLE2ID[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
oguzkaygun
Yak Posting Veteran
53 Posts |
Posted - 2011-10-08 : 11:16:20
|
| HelloI did like belowSelect name, table2id ( select top 1 columname From table2 t2 Where t2.id =t1.table2id ) from table1 t1 |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-10-08 : 11:18:45
|
quote: Originally posted by oguzkaygun HelloI did like belowSelect name, table2id ( select top 1 columname From table2 t2 Where t2.id =t1.table2id ) from table1 t1
ok you want only one record to be displayed of duplicates? then isnt distinct enough?SELECT DISTINCT t1.NAME,t2.NAMEFROM Table1 t1JOIN Table2 t2ON t2.ID = t1.TABLE2ID use of subqueries can hurt performance when you're dealing with large data------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
oguzkaygun
Yak Posting Veteran
53 Posts |
Posted - 2011-10-08 : 11:26:56
|
| HelloYes. one record for dublicate records.But if they are in table2.if there are two apple as name at table1, grid should be display two records.like belowapple yellowapple yellow. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-10-08 : 11:30:41
|
quote: Originally posted by oguzkaygun HelloYes. one record for dublicate records.But if they are in table2.if there are two apple as name at table1, grid should be display two records.like belowapple yellowapple yellow.
distinct will return only one set of values from record.------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
oguzkaygun
Yak Posting Veteran
53 Posts |
Posted - 2011-10-08 : 11:34:45
|
| ok. i see now. thank you for help. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-10-08 : 12:34:34
|
| welcome------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
jassi.singh
Posting Yak Master
122 Posts |
Posted - 2011-10-10 : 02:28:22
|
| Hi,Try following select table1.Id, table1.Name,Table2.name from table1 inner join table2 on table1.Table2ID = table2.IdPlease mark answer as accepted if it helped you.Thanks,Jassi Singh |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-10-10 : 02:31:51
|
quote: Originally posted by jassi.singh Hi,Try following select table1.Id, table1.Name,Table2.name from table1 inner join table2 on table1.Table2ID = table2.IdPlease mark answer as accepted if it helped you.Thanks,Jassi Singh
Can you AT LEAST try this for posted sample data and see what you got before suggesting anything?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|