开发者

SQL Query - select data from table A based on two fields in table B

开发者 https://www.devze.com 2023-01-18 11:54 出处:网络
I have two tables: A: [ date, step, status, ... ] B: [ date, step, name, ... ] I want to get result in form of

I have two tables:

A:
[ date,
 step,
 status,
 ... ]

B:
[ date,
  step,
  name,
  ... ]

I want to get result in form of

[date, step, name]

based on status parameter. I can easly get data from table A using following query:

Select date, step From A Where status='1'

and the result would be like:

1. 2010-09-12; 5
2. 2010-09-13; 3
...

but i dont know how to use it to find names from table B corresponding 开发者_运维百科to those records.

Thanks for any help.


Select B.Name
From A
Inner Join B
  On A.date = B.date
  And A.step = B.step
Where A.status = '1'


You need to join the two tables. From your question i immagine that you want to do something like this:

Select a.date, a.step, b.name  
From A a, B b
Where a.status='1' and a.date = b.date and a.step = b.step

You can read mor on joining table in Wikipedia or this description of sql joins

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号