Click here to Skip to main content
15,913,685 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have two tables in both tables i have one common column and i want join these two table with that common column in grid view for eg
table1
------
id,
name,
city

table2
------
id,
address

i want those columns which have the same id in the both tables.

i used
SQL
select * from table1 inner join table2 on table1.id = table2.id

but this is showing an error of invalid object name
Posted
Updated 7-Jun-12 0:33am
v2
Comments
Mantu Singh 7-Jun-12 6:29am    
mention column names of both tables and what columns you want in the output then the query could be framed properly.........?

1 solution

Try:
SQL
SELECT t1.id, t1.name, t1.city , t2.address
FROM [YourDatabaseName].[dbo].[table1] AS t1 LEFT JOIN [YourDatabaseName].[dbo].[table2] AS t2 on t1.id = t2.id


This mean: select all data from table1 and corresponding data from table2.
 
Share this answer
 
v2
Comments
Rini Agrawal 7-Jun-12 6:43am    
again same error invalid object name table1 is coming...
Maciej Los 7-Jun-12 14:04pm    
Probably you need to specify a database name. Take a look now.
codeBegin 8-Jun-12 2:19am    
+5
Maciej Los 8-Jun-12 6:52am    
Thank you, codeBegin ;)

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