Author |
Topic |
niranjan1988
Starting Member
5 Posts |
Posted - 2013-05-08 : 14:22:26
|
I hAVE 2 TABLES...Table1-------c1 c2NUll heloTable 2--------c1 c2ranjan nullI want to display as ...c1 c2ranjan helo |
|
chadmat
The Chadinator
1974 Posts |
Posted - 2013-05-08 : 14:28:45
|
There is nothing to join these tables on. Given the limited dataset, you could create a Cartesian product, and get what you want, but I don't think that that would be what you want if there is more data in the tables.-Chad |
|
|
niranjan1988
Starting Member
5 Posts |
Posted - 2013-05-08 : 14:33:02
|
Assume that c3 colum is key column to join both tables...Table1-------c1 c2 c3NUll helo K1Table 2--------c1 c2 C3ranjan null K1 |
|
|
chadmat
The Chadinator
1974 Posts |
Posted - 2013-05-08 : 14:35:58
|
SELECT t2.c1, t1.c2FROM Table1 t1 join Table2 t2 on t1.c3=t2.c3-Chad |
|
|
niranjan1988
Starting Member
5 Posts |
Posted - 2013-05-08 : 14:40:30
|
output will beNull heloranjan NullBut i need ranjan helo |
|
|
MIK_2008
Master Smack Fu Yak Hacker
1054 Posts |
Posted - 2013-05-08 : 14:53:12
|
declare @t1 table (col1 varchar(10),col2 varchar(10),col3 varchar(10))declare @t2 table (col1 varchar(10),col2 varchar(10),col3 varchar(10))insert into @t1 values (null,'helo','K1')insert into @t2 values ('ranjan',NULL,'K1')SELECT Max(t2.col1), Max(t1.col2)FROM @t1 t1 join @t2 t2 on t1.col3=t2.col3CheersMIK |
|
|
niranjan1988
Starting Member
5 Posts |
Posted - 2013-05-08 : 14:57:38
|
how u r applying the max function to varchar column? |
|
|
chadmat
The Chadinator
1974 Posts |
Posted - 2013-05-08 : 15:10:13
|
quote: Originally posted by MIK_2008 declare @t1 table (col1 varchar(10),col2 varchar(10),col3 varchar(10))declare @t2 table (col1 varchar(10),col2 varchar(10),col3 varchar(10))insert into @t1 values (null,'helo','K1')insert into @t2 values ('ranjan',NULL,'K1')SELECT Max(t2.col1), Max(t1.col2)FROM @t1 t1 join @t2 t2 on t1.col3=t2.col3CheersMIK
Why MAX()?-Chad |
|
|
chadmat
The Chadinator
1974 Posts |
Posted - 2013-05-08 : 15:11:57
|
quote: Originally posted by niranjan1988 output will beNull heloranjan NullBut i need ranjan helo
It shouldn't be if you have described your data properly.declare @t1 table (col1 varchar(10),col2 varchar(10),col3 varchar(10))declare @t2 table (col1 varchar(10),col2 varchar(10),col3 varchar(10))insert into @t1 values (null,'helo','K1')insert into @t2 values ('ranjan',NULL,'K1')SELECT t2.col1, t1.col2FROM @t1 t1 join @t2 t2 on t1.col3=t2.col3-Chad |
|
|
niranjan1988
Starting Member
5 Posts |
Posted - 2013-05-08 : 15:53:39
|
it worked.. thanks |
|
|
UnemployedInOz
Yak Posting Veteran
54 Posts |
Posted - 2013-05-09 : 02:00:46
|
declare @t1 table (col1 varchar(10),col2 varchar(10),col3 varchar(10))declare @t2 table (col1 varchar(10),col2 varchar(10),col3 varchar(10))insert into @t1 values (null,'helo','K1')insert into @t1 values (null,'helo2','K2')insert into @t2 values ('ranjan',NULL,'K1')insert into @t2 values ('ranjan2',NULL,'K2')SELECT max(t2.col1), max(t1.col2)FROM @t1 t1 join @t2 t2 on t1.col3=t2.col3group by t1.col3,t2.col3 |
|
|
|