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 |
|
amirs
Constraint Violating Yak Guru
260 Posts |
Posted - 2010-04-01 : 05:21:58
|
| I have select records of three table like A,B,C their following structureAa_col1 a_col2 a_col3 a_col4 , date Bb_col1 b_col2 b_col5 b_col6Cc_col1 c_col9 c_col5 c_col10I have find the records to join a table A,B the index colomn isA.a_col1=B.b_col1 and A.a_col2=B.b_col2 and between date colom of A to use inner joinand i have get records of colom c_col9 in table C to comapre table A and B is A.a_col1=C.b_col1 and B.a_col5=C.b_col5So how i can write the query |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-04-01 : 05:39:54
|
its straight forward joinSELECT A.*,B.*,C.c_col9 FROM AJOIN BON A.a_col1=B.b_col1 and A.a_col2=B.b_col2 JOIN CON A.a_col1=C.b_col1 and B.a_col5=C.b_col5 ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
amirs
Constraint Violating Yak Guru
260 Posts |
Posted - 2010-04-01 : 23:50:11
|
| thanks to replay following is my qeryselect a.t_date, a.col1, '0' as size1, a.col2, a.col3, a.col4, b.col5,c.col6 from tabl1 a join tabl2 b on a.col1=b.col1 join tabl3 c on c.col8='ABC' and c.col1=a.col1 and c.col5 =b.col5 where a.t_date between '03/30/2010' and '03/30/2010' and c.date <='03/30/2010' and (c.t_date1 <= '03/30/2010' or c.t_date1 > 1)to join a tabl1 and tabl2 is dispaly 2000 records and i have join tabl3 dispaly 13000 records this is wrong my codition is get a result to join a table tabl1 and tabl2 to matching colom of col1 and i have join to get one colom of tabl1 and second colom of tabl2 and this join a tabl3 hence dispaly only matching record colm6 of tabl 3 otherwise it is null of my where condition.so how can write the query. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-04-02 : 02:04:32
|
| it may be because you've one to many relationship with tabl3. see if you've multiple records existing per col1,col5 combination in tbl3------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|
|
|