User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the MS SQL section within the Web Development category of DaniWeb, a massive community of 425,982 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 1,644 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our MS SQL advertiser: Programming Forums
Views: 1351 | Replies: 5
Reply
Join Date: Sep 2006
Posts: 104
Reputation: bhavna_816 is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
bhavna_816 bhavna_816 is offline Offline
Junior Poster

Extract columns from two independent table in SQL Server 2005?

  #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,
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Aug 2005
Location: Ohio
Posts: 204
Reputation: plazmo is an unknown quantity at this point 
Rep Power: 4
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?

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

this combines both tables
Reply With Quote  
Join Date: Mar 2008
Posts: 119
Reputation: sonia sardana is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
sonia sardana sonia sardana is offline Offline
Junior Poster

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

  #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 6:47 pm. Reason: Keep It Organized - please use [code] tags
Reply With Quote  
Join Date: Mar 2008
Posts: 119
Reputation: sonia sardana is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
sonia sardana sonia sardana is offline Offline
Junior Poster

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

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

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

  #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 1:53 pm. Reason: Keep It Organized - please use [code] tags
Reply With Quote  
Join Date: Apr 2008
Posts: 4
Reputation: aardvax01 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
aardvax01 aardvax01 is offline Offline
Newbie Poster

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

  #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 7:14 am.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb MS SQL Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Other Threads in the MS SQL Forum

All times are GMT -4. The time now is 11:28 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC