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
 SQL Server 2005 Forums
 .NET Inside SQL Server (2005)
 combine sql query result columns?

Author  Topic 

asksql
Starting Member

11 Posts

Posted - 2008-06-02 : 21:14:16
This might be a question with an extremely easy answer.. I don't know but here I go.

I want a report with lets say

|A | B | C |
----------------



I can easily figure out the sql statements to find the columns A, B and C individually but how do I combine them?

so lets say I have

select cola as A from table1 where ....

select colb as B from table2...

They are not from the same table so I cannot combine them either (I cannot do select cola, colb from table1 etc.. )

How would I do this? Am I missing something?

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-06-02 : 21:30:47
Can you join the tables together? Are they related at all?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Database maintenance routines:
http://weblogs.sqlteam.com/tarad/archive/2004/07/02/1705.aspx
Go to Top of Page

asksql
Starting Member

11 Posts

Posted - 2008-06-03 : 01:18:52
I'm trying to find relationships among them and I'm having a hard time finding any.

Even if I do find relationships (one of them does have a many-to-many relationship) I'm having a hard time doing a join because I want all the columns in both the tables no matter what...maybe I'm going about this wrong... not sure..
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-06-03 : 11:05:40
Show us a data example.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Database maintenance routines:
http://weblogs.sqlteam.com/tarad/archive/2004/07/02/1705.aspx
Go to Top of Page

asksql
Starting Member

11 Posts

Posted - 2008-06-04 : 21:01:15
I worked with SQL a long long time ago and don't even remember a lot of things. Could you please explain the procedure for doing a join?

This is what I recall so far..
1) find the tables which contain the data you need
2) find the columns that you need
3) find a common column (preferrably a key ) to join your tables..
ie. where table1.id = table2.id

is that it? Am I on the right path?

What else would I need?

Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-06-05 : 12:48:33
You are on the right path.

If you show us a data example, we can better help you out.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Database maintenance routines:
http://weblogs.sqlteam.com/tarad/archive/2004/07/02/1705.aspx
Go to Top of Page
   

- Advertisement -