| Author |
Topic |
|
ishchopra
Starting Member
24 Posts |
Posted - 2011-10-19 : 07:32:49
|
| Hello Experts,Here is my problem:I have two tables which have identical columns but different data. I am just wondering if i can bring in all the records from Table 1 adjacent to Table 2.For Example:Table 1 have 3 records Table 2 have 5 recordsI need output like thisTable 1 ..............Table 2ABC.....................DEFDEF.....................JKLGEH.....................ABCNull....................GEHNull....................XYZPlease let me know if that is achievableI need it for comparison but all the records not just commonRegards,Ish |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-10-19 : 07:37:45
|
| sounds like what you need is full outer join between tables on common fields------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
ishchopra
Starting Member
24 Posts |
Posted - 2011-10-19 : 07:44:25
|
| Can you please explain more on this ? |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-10-19 : 08:18:05
|
| can you please provide sample data and explain what output you want so that i can give query accordingly------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
ishchopra
Starting Member
24 Posts |
Posted - 2011-10-19 : 09:05:56
|
| Hey apologize for late reply,Here you goTable NamesWin41Win42Name of Fields i need from both tables:IDMarginAnd mind it i am trying to do this in Access as well as sql.Please let me know if you need anything else |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-10-19 : 09:35:39
|
| [code]SELECT t1.Margin,t2.MarginFROM table1 t1FULL OUTER JOIN Table2 t2On t2.id = t1.id[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
ishchopra
Starting Member
24 Posts |
Posted - 2011-10-19 : 10:09:23
|
| FULL OUTER JOIN doesnt work in Access.. do you have any alternative ? |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-10-19 : 10:12:12
|
| if you're looking at Access query, please post in access forums------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
sqlmaster555112
Starting Member
13 Posts |
Posted - 2011-10-19 : 10:59:42
|
| Hi Ish,I think this should work,SELECT t1.id,t1.Margin,t2.MarginFROM table1 t1inner JOIN Table2 t2On t2.id = t1.id@sqlmasterhttp://www.intelcs.com/SQL_Server_Consultant.aspx |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-10-20 : 00:30:50
|
quote: Originally posted by sqlmaster555112 Hi Ish,I think this should work,SELECT t1.id,t1.Margin,t2.MarginFROM table1 t1inner JOIN Table2 t2On t2.id = t1.id@sqlmasterhttp://www.intelcs.com/SQL_Server_Consultant.aspx
it wont as per OPs outputit wont fetch unmatching records at all------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
sqlmaster555112
Starting Member
13 Posts |
Posted - 2011-10-20 : 10:36:07
|
| The answer posted on that link was for the values where its not written null coz as far as I remember previously Null was not written in the Question.here is the solution to the problem with null stuff...........Suppose we have two tables data and table2 each with 2 columns of the formData Table2id Value id Valuesss1 10 1 542 20 2 783 8 3 2134 87 4 2545 51 5 956 657 568 66then write this querySELECT *FROM data INNER JOIN table2 ON data.ID=table2.IDUnionSELECT *FROM data LEFT JOIN table2 ON data.ID = table2.IDWHERE (table2.id) is nullUnionSELECT *FROM data RIGHT JOIN table2 ON data.ID = table2.IDWHERE (data.id) is null;it is a substitute for Full outer Join in SQL serverTry this it has given the right answer to me.@sqlmasterhttp://www.intelcs.com/SQL_Server_Consultant.aspx |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-10-21 : 00:46:35
|
quote: Originally posted by sqlmaster555112 The answer posted on that link was for the values where its not written null coz as far as I remember previously Null was not written in the Question.here is the solution to the problem with null stuff...........Suppose we have two tables data and table2 each with 2 columns of the formData Table2id Value id Valuesss1 10 1 542 20 2 783 8 3 2134 87 4 2545 51 5 956 657 568 66then write this querySELECT *FROM data INNER JOIN table2 ON data.ID=table2.IDUnionSELECT *FROM data LEFT JOIN table2 ON data.ID = table2.IDWHERE (table2.id) is nullUnionSELECT *FROM data RIGHT JOIN table2 ON data.ID = table2.IDWHERE (data.id) is null;it is a substitute for Full outer Join in SQL serverTry this it has given the right answer to me.@sqlmasterhttp://www.intelcs.com/SQL_Server_Consultant.aspx
thats why i suggested full outer join in my first suggestions itself but its no available in acces and hence has to be simulated as above------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|