Extract columns from two independent table in SQL Server 2005?

Please support our MS SQL advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2006
Posts: 116
Reputation: bhavna_816 is an unknown quantity at this point 
Solved Threads: 0
bhavna_816 bhavna_816 is offline Offline
Junior Poster

Extract columns from two independent table in SQL Server 2005?

 
0
  #1
Apr 11th, 2008
I want to get two columns data from two tables which are not dependent to each other i.e. no key common in both they are not related to each other.

I can't use JOIN because it needs where clause which uses a common field from both tables.
I just want one column from one table and one column from another and display it.
how can do it?
some unions or any other syntax for that?

Thanks in advance,
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 206
Reputation: plazmo is an unknown quantity at this point 
Solved Threads: 16
plazmo's Avatar
plazmo plazmo is offline Offline
Posting Whiz in Training

Re: Extract columns from two independent table in SQL Server 2005?

 
0
  #2
Apr 11th, 2008
select * from table1, table2

this combines both tables
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 324
Reputation: sonia sardana has a little shameless behaviour in the past 
Solved Threads: 7
sonia sardana sonia sardana is offline Offline
Posting Whiz

Re: Extract columns from two independent table in SQL Server 2005?

 
0
  #3
Apr 11th, 2008
  1. CREATE TABLE name1(name VARCHAR)
  2. INSERT INTO name1 VALUES('A')
  3. INSERT INTO name1 VALUES('B')
  4.  
  5. CREATE TABLE name2(name VARCHAR)
  6. INSERT INTO name2 VALUES('B')
  7. INSERT INTO name2 VALUES('C')
  8.  
  9. SELECT name FROM name1
  10. UNION
  11. SELECT name FROM name2

UNION will eliminate duplicates,If u want to retain duplicates Use UNION ALL.

Is that worked for u?If face any probs reply.
Last edited by peter_budo; Apr 11th, 2008 at 7:47 pm. Reason: Keep It Organized - please use [code] tags
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 324
Reputation: sonia sardana has a little shameless behaviour in the past 
Solved Threads: 7
sonia sardana sonia sardana is offline Offline
Posting Whiz

Re: Extract columns from two independent table in SQL Server 2005?

 
0
  #4
Apr 12th, 2008
Can u Paste the tables & specify which column to retrieve, so that I can help u out.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 4
Reputation: aardvax01 is an unknown quantity at this point 
Solved Threads: 0
aardvax01 aardvax01 is offline Offline
Newbie Poster

Re: Extract columns from two independent table in SQL Server 2005?

 
0
  #5
Apr 14th, 2008
Hi Bhavna

I think that you can do it yourself
There is something called Non -Equi Joins Which needs the where clause which you want
I think you can use Logical Operators to accomplish what you want

There is one Example of Employee and Salary Tables ( a famous one)

Hope this will help you

Ok lemme give an Example -- Suppose there are two tables with name as Emp and Salary



  1. SELECT E.Last_Name, E.Sal, S.Category
  2. FROM Emp E, Salary S
  3. WHERE E.Sal BETWEEN S.Highest AND S.Lowest


And this example is taking oracle in consideration ..
there might be some other way of using joins in SQL Server
I will have a look and will edit this post once more
Last edited by peter_budo; Apr 17th, 2008 at 2:53 pm. Reason: Keep It Organized - please use [code] tags
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 4
Reputation: aardvax01 is an unknown quantity at this point 
Solved Threads: 0
aardvax01 aardvax01 is offline Offline
Newbie Poster

Re: Extract columns from two independent table in SQL Server 2005?

 
0
  #6
Apr 18th, 2008
  1. SELECT * FROM Employees


I posted this message to learn the [code tags]
Last edited by aardvax01; Apr 18th, 2008 at 8:14 am.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the MS SQL Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC