Filter Records form Different table

Posted by Aspbimal under Sql Server on 6/20/2011 | Points: 10 | Views : 1560 | Status : [Member] | Replies : 7
hi

how to retrive records from different two tables using sql query




Responses

Posted by: Lakn2 on: 6/20/2011 [Member] Starter | Points: 25

Up
0
Down
select t1.col1,t1.col2.....,t2.col1,t2.col2..... from table t1 inner join table t2 on t1.col1=t2.col1 


or

select * from table1,tabel2....


Thanks&Regards
LakshmiNarayana Nalluri.

Aspbimal, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ndebata on: 6/20/2011 [Member] Starter | Points: 25

Up
0
Down
Hi
If those two tables are related, then join them, then apply filter
to know how to join tables
http://dotnetslackers.com/articles/sql/SQL-SERVER-JOINs.aspx

Aspbimal, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vforvijay on: 6/21/2011 [Member] Starter | Points: 25

Up
0
Down
hi...
Try this query
select a.c1,a.c2,a.c3,a.c4,b.b1 from table1 as c1,table2 as b1


http://vbdotnetaddict.blogspot.com

Aspbimal, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sriramnandha on: 6/26/2012 [Member] Starter | Points: 25

Up
0
Down
Hi,

select a.empid,a.empname,b.empaddress,b.empsalary from employee a inner join employeesalary b 


on a.empid=b.empid



Hope this will help

Regards




sriram

Aspbimal, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Muralidosscm on: 7/4/2012 [Member] Starter | Points: 25

Up
0
Down
select a.name from employee a join employeesalary b on a.name=b.name

Regards
Muralidoss M

Aspbimal, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: saficreator-10970 on: 7/4/2012 [Member] Starter | Points: 25

Up
0
Down
if you need records from both the table based on condition, you may use inner join as like below,

select a.column1,a.column2,b.column1,b.column2 from table1 a 

inner join table2 b on a.column1=b.column1 where 1=1


or if you need records from both the table without any condition, you may use union all as like below,

select column1,column2 from table1

union all
select column1,column2 from table1


Regards,
Mohamed Shafee M

Aspbimal, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Patel28rajendra on: 7/5/2012 [Member] Starter | Points: 25

Up
0
Down
Hi

you can use Joins for that
Like Left join ,Right Join ,Inner Join ,Outer Join etc.



R D Patel

Aspbimal, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response