Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 how select the unique column names

Author  Topic 

manshafmkd
Starting Member

3 Posts

Posted - 2012-05-26 : 04:45:04
how select the unique column names from 4 tables

i using the code

select *
from t1
where exists(select * from t2 where t2.col1 = t1.col1 and t2.col1 = t1.col1)

but its only for two table connection

i want four table connection

Please give a help

slimt_slimt
Aged Yak Warrior

746 Posts

Posted - 2012-05-26 : 16:22:07
Please be so kind and provide additional explanation what you want to achieve.
if you want all the names from 4 tables, just list the name of columns. eg.:


select
table1.column1
,table1.column2
,table2.column1
,table2.column3
,table3.column4
,table4.column1
from
table1
join table2
on table1.column1 = table2.column1
join table3
on table1.column1 = table3.column1
Go to Top of Page

manshafmkd
Starting Member

3 Posts

Posted - 2012-05-27 : 02:50:59
Actually i have a unique column in all table ,if i enter the unique column value to show the related table unique column value status

quote:
Originally posted by slimt_slimt

Please be so kind and provide additional explanation what you want to achieve.
if you want all the names from 4 tables, just list the name of columns. eg.:


select
table1.column1
,table1.column2
,table2.column1
,table2.column3
,table3.column4
,table4.column1
from
table1
join table2
on table1.column1 = table2.column1
join table3
on table1.column1 = table3.column1


Go to Top of Page

manshafmkd
Starting Member

3 Posts

Posted - 2012-05-27 : 03:36:22
select *
from tb_apartmentrent
where exists(select * from tb_renovteapprt where tb_renovteapprt.orderid = tb_apartmentrent.orderid and tb_renovteapprt.orderid = tb_apartmentrent.orderid)

this is my query actually i have toatal 5 tables

the tables are

tb_apartment,tb_renovteapprt,cancelappartment,tb_completeapartment,tb_validateapartment

each table have a unique colum name orderid

i want to check the orderid renovated,canceled,completed and validated

but my query only the relation betweeb two tables ,but i need the relation between 5 tables


Please give me the solution


Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-05-27 : 11:36:43
unless you provide proper information to show how tables are related we wont be able to help.

Post sample data and output in below format and then we will take a look

http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -