[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

SQL Command

Posted on 2011-02-22
5
Medium Priority
?
212 Views
Last Modified: 2012-06-21
I have three tables as follows;

table1
t1id(pk)  wname        ver
1          some text       0

table2
t2ID(pk)  t1id(FK)
10            1
11            1
12            1

table3
woIdP(pk)  t2id(FK) status
1000           10             100
1001           11              1
1002           12              2

How can I select all records from table1 if the status of all the records from table3=100 by relating all the three tables? I am using sql server 2005.

pls help

ayha
0
Comment
Question by:ayha1999
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 18

Expert Comment

by:sventhan
ID: 34953494
select a.*, b.*,c.*
from table1 a , table2 b, table3 c
where a.t1id = b.t2id
and b.t2id = b.t2id
and c.status = 100
0
 
LVL 18

Expert Comment

by:sventhan
ID: 34953506

< How can I select all records from table1 if the status of all the records from table3=100 by relating all the three tables?

select a.t1id,a.wname,a.ver
from table1 a , table2 b, table3 c
where a.t1id = b.t2id
and b.t2id = b.t2id
and c.status = 100
0
 
LVL 4

Expert Comment

by:jmnf
ID: 34953590
Exactly the same answer as sventhan

SELECT      T1.t1id,
            T1.wname,
            T1.ver
FROM      table1 AS T1,
            table2 AS T2,
            table3 AS T3
WHERE      T3.status = 100
      AND      T2.t2id = T3.t2id
      AND T1.t1id = T2.t1id
0
 
LVL 32

Accepted Solution

by:
Ephraim Wangoya earned 1000 total points
ID: 34953988
two ways
select * 
from table1
inner join table2 on table2.t2ID = table1.t1id
inner join table3 on table3.t2id = table2.t2ID
where status = 100

Open in new window

select * 
from table1
inner join table2 on table2.t2ID = table1.t1id
inner join table3 on (table3.t2id = table2.t2ID and table3.status = 100)

Open in new window

0
 
LVL 6

Expert Comment

by:Rajesh_mj
ID: 34958277
Please try this:
SELECT T1.T1ID,T1.wname,T1.Ver
FROM table1 T1 INNER JOIN table2 T2 ON T1.t1Id = T2.t1Id
             INNER JOIN table3 T3 ON T2.t2ID = T3.T2ID
WHERE T3.Status = 100
SELECT T1.T1ID,T1.wname,T1.Ver
FROM table1 T1 INNER JOIN table2 T2 ON T1.t1Id = T2.t1Id 
	       INNER JOIN table3 T3 ON T2.t2ID = T3.T2ID
WHERE T3.Status = 100

Open in new window

0

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question