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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Need help in Union Two tables side by side.

Author  Topic 

osirisa
Constraint Violating Yak Guru

289 Posts

Posted - 2009-07-06 : 11:23:12
Ok. Maybe this is a better example of what I am trying to do.

Select id, Location_Code, Responsibility_Begins_With, Approver_Main, AppMain_UserId, Approver_BackUP,AppBackUp_UserId
From Approver_Matrix
where Responsibility_Begins_With like 'DR 200% Super User'
Select Application_Name, Responsibility_Key, Responsibility_Name
from responsibilities
Where Responsibility_Name like 'DR 200% Super User'


-----------------------------
I need to select this Two Tables: approver Matrix and Responsibilities. But instead of union all Vertical. I need to have this two selection side by side. So it will look something like this:

Select id, Location_Code, Responsibility_Begins_With, Approver_Main, AppMain_UserId, Approver_BackUP,AppBackUp_UserId,Application_Name, Responsibility_Key, Responsibility_Name 
From Approver_Matrix and from responsibilities
where Responsibility_Begins_With like 'DR 200% Super User'
Were Responsibility_Name like 'DR 200% Super User'


Thank you for the help!!!

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2009-07-06 : 11:36:30
Will Responsibility_Begins_With and Responsibility_Name have the same values? Can we join both those tables based on these fields...if yes, try this

SELECT a.id, 
a.location_code,
a.responsibility_begins_with,
a.approver_main,
a.appmain_userid,
a.approver_backup,
a.appbackup_userid,
b.application_name,
b.responsibility_key,
b.responsibility_name
FROM approver_matrix a
INNER JOIN responsibilities b
ON a.responsibility_begins_with = b.responsibility_name
WHERE a.responsibility_begins_with LIKE 'DR 200% Super User'
Go to Top of Page

osirisa
Constraint Violating Yak Guru

289 Posts

Posted - 2009-07-06 : 12:08:22
Thank you vijayisonly. I think I should it give you an example of data for each table. You see the problem is that this two tables don't have anything in common except the fact that both of them query out the results based on 'DR 200% Super User'

Bothe IMPORTANT they don't have anything in common, there is not any column that you can join it under. This is why I wanted to merge both tables based on their result using :
Select Application_Name, Responsibility_Key, Responsibility_Name
from responsibilities
Where Responsibility_Name like 'DR 200% Super User' As Main Table

Thanks for the help
Go to Top of Page

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2009-07-06 : 12:12:34
Can you show us the values in columns Responsibility_Name and Responsibility_Begins_With ....if u are able to use LIKE on both these fileds..you should be able to join them. If you show us the data , it'll help
Go to Top of Page

osirisa
Constraint Violating Yak Guru

289 Posts

Posted - 2009-07-06 : 12:38:17
Approver Table Results
Select id, Location_Code, Responsibility_Begins_With, Approver_Main, AppMain_UserId, Approver_BackUP,AppBackUp_UserId
From Approver_Matrix
where Responsibility_Begins_With like 'DR 200% Super User'

id----location--Resp_begin_With-----------Approver Name -------Approverid-------BackUp_name-----------BackUp_id
1 200 DR 200% Super User Jean Marc Lombrez xxoxoxox Jean-Luc Richard xoxoxoxoxo
80 200 DR 200% Super User Jean Marc Lombrez xoxoxoxo Jean-Luc Richard xoxoxoxoox
254 200 DR 200 HR Super User Didier Langree xoxooxox Hans Peter Blokkum xoxoxoxoxo



------------------------
Responsibility Table Results
Select Responsibility_Key, Responsibility_Name
from responsibilities
Where Responsibility_Name like 'DR 200% Super User'

[code]
Responsibility_key------------Responsibility_Name
DR_200_BOM_SUPER_USER DR 200 BOM Super User
DR_200_ENG_SUPER_USER DR 200 ENG Super User
DR_200_IMC_SUPER_USER DR 200 CON Customers Online Super User
DR_200_AP_SUPER_USER DR 200 AP Super User


Thank you again vijaysionly :)
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2009-07-06 : 12:50:41
How do you propose that you merge data with nothing in common?

Like this?


Table1

id Value
1 Apples
2 Bananas
3 Cherries

Table2

id Value
1 Aretha
2 Benjamin
3 Celia

So the result is?

id1 Value1 id2 Value2
1 Apples 1 Aretha
1 Apples 2 Benjamin
1 Apples 3 Celia
2 Bananas 1 Aretha
2 Bananas 2 Benjamin
2 Bananas 3 Celia
3 Cherries 1 Aretha
3 Cherries 2 Benjamin
3 Cherries 3 Celia

?????????????????????????????????????????????????????????????








Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page
   

- Advertisement -