Click here to Skip to main content
16,019,983 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi sir,

i am taking two tables i.e., table1 and table2. if i execute table1 result is

Select * from table1

Name    class

Ajay	  8
raju	  9
Surya	  7
ajay raju 10 


and execute table2

select * from table2

Dept       Gen

Accounts    M
Management  F
Research    M
Developing  M
designing   M


i want to take dept column from table2

that i write query like

select dbo.table1.name,dbo.table1.ID,dbo.table2.dept from table1,table2

Then result is:

Name   ID       Dept

Ajay	    8	Accounts
Ajay	    8	Management
Ajay	    8	Research
Ajay 	    8	Developing
Ajay	    8	designing
Raju	    9	Accounts
Raju	    9	Management
Raju	    9	Research
Raju	    9	Developing
Raju	    9	designing
Surya	    7	Accounts
Surya	    7	Management
Surya	    7	Research
Surya	    7	Developing
Surya	    7	designing
Ajay raju   10	Accounts
Ajay raju   10	Management
Ajay raju   10	Research
Ajay raju   10	Developing
Ajay raju   10	designing


this time it display result as number of times.

but my aim is result display like:

Name      ID       Dept

Ajay	  8    Accounts  
raju      9    Management     
Surya     7    Research 
ajay raju 10   Developing
null     null  designing 



Please give a solution. and please give a sample select query for this

Thank you sir.
Posted
Updated 4-Sep-10 0:29am
v2

It's really difficult for anyone to help you until you present the full problem out here.

Based on just what you have asked here, everything from both the table1 & table2 in a single query that has no common column:
SQL
Select * From Table1, Table2
 
Share this answer
 
Hi Ajay,

Its not possible to get your output.You can give any common column in both the table means is possible.
For example 'ID' is the common column in two tables then use the following query

select T1.ID,T1.Name,T2.Dept from Table1 T1,Table2 T2 where T1.ID=T2.ID
(or)
select Table1.ID,Table1.Name,Table2.Dept from Table1 inner join Table2 on Table1.ID=Table2.ID


Cheers :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900