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,

Recommended Answers

All 5 Replies

select * from table1, table2

this combines both tables

create table name1(name varchar)
insert into name1 values('A')
insert into name1 values('B')

create table name2(name varchar)
insert into name2 values('B')
insert into name2 values('C')

select name from name1
UNION
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.

Can u Paste the tables & specify which column to retrieve, so that I can help u out.

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

SELECT E.Last_Name, E.Sal, S.Category
FROM Emp E, Salary S
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

SELECT * FROM Employees

I posted this message to learn the [code tags]

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.