douxiong0668 2016-08-09 22:36 采纳率: 100%
浏览 10

从另一个查询创建查询

Looking for a little assistance.. I am trying to create a query to use as a parameters for another query.

Here is what I am attempting..

I think I didnt make myself clear enough (big surprise) ignore any hard coded data in the queries, they first part is using variables sent in from the search page.

The second query is what I really need to know how to accomplish. If I have to figure out how to generate the sql for selecting however many records i got in the first query,,,

SELECT distinct Invoice_Number   FROM invoices_details where check_number = '9999' and taxid = '9999999'

Which returns 3 invoice numbers..

What I need to do is to use those invoice numbers in another select...

***Select claim_details from claim_d where invoice in ('xxxx','yyyy','zzzz')***

I am at a loss on if this is even possible..

Any help would be appreciated.

Thanks

Kevin

  • 写回答

1条回答 默认 最新

  • douwen4178 2016-08-09 22:38
    关注

    You can wrap that SELECT in your IN clause which is also known as subquery like

    Select claim_details 
    from claim_d 
    where invoice in (
    SELECT Invoice_Number   
     FROM invoices_details 
     where check_number = '9999' 
     and taxid = '9999999'
    )
    

    (OR) using a INNER JOIN like below (recommended approach)

    select distinct claim_details 
    from claim_d c
    join invoices_details i ON c.invoice = i.Invoice_Number
    where i.check_number = '9999' 
    and i.taxid = '9999999';
    
    评论

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改