943,752 Members | Top Members by Rank

Ad:
  • MS SQL Discussion Thread
  • Unsolved
  • Views: 3608
  • MS SQL RSS
Apr 11th, 2008
0

Extract columns from two independent table in SQL Server 2005?

Expand Post »
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,
Reputation Points: 10
Solved Threads: 0
Junior Poster
bhavna_816 is offline Offline
116 posts
since Sep 2006
Apr 11th, 2008
0

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

select * from table1, table2

this combines both tables
Reputation Points: 23
Solved Threads: 16
Posting Whiz in Training
plazmo is offline Offline
206 posts
since Aug 2005
Apr 11th, 2008
0

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

sql Syntax (Toggle Plain Text)
  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
Reputation Points: 0
Solved Threads: 8
Posting Whiz
sonia sardana is offline Offline
326 posts
since Mar 2008
Apr 12th, 2008
0

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

Can u Paste the tables & specify which column to retrieve, so that I can help u out.
Reputation Points: 0
Solved Threads: 8
Posting Whiz
sonia sardana is offline Offline
326 posts
since Mar 2008
Apr 14th, 2008
0

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

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



sql Syntax (Toggle Plain Text)
  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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
aardvax01 is offline Offline
4 posts
since Apr 2008
Apr 18th, 2008
0

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

SQL Syntax (Toggle Plain Text)
  1. SELECT * FROM Employees


I posted this message to learn the [code tags]
Last edited by aardvax01; Apr 18th, 2008 at 8:14 am.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
aardvax01 is offline Offline
4 posts
since Apr 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in MS SQL Forum Timeline: Info needed regarding SQL server 2005
Next Thread in MS SQL Forum Timeline: Error Code 424: object required





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC