Usage instance SQL for Union all

Source: Internet
Author: User

---Union all usage instance SQL
SELECT TOP (PERCENT) ID, bid_user_id, UserName, amount, Createtime, Borrowtype
from (SE Lect bid.id, bid.bid_user_id, Reg. UserName, Bid.amount, bid.createtime, ' common standard ' as Borrowtype
from dbo. Yyd_borrow_bidrecord as bid
INNER JOIN dbo. Yyd_users_reginfo as Reg on reg.id = bid.bid_user_id
WHERE (bid.id not in (SELECT bid
from dbo. Hur_newplanloan_itemloan) and (Bid.id not in
(SELECT bidid from dbo. hur_product_matching))

UNION all

SELECT bid.id, Bid.userid, Reg. UserName, Bid.amount, Bid.createtime, ' plan ' as Borrowtype
from dbo. Hur_newplanloan_bidrecord as bid
INNER JOIN dbo. Yyd_users_reginfo as Reg on reg.id = Bid.userid

UNION all

SELECT Buy.buyid, Buy.userid, Reg. UserName, Buy.amount, buy.createdate, ' buy ' as Borrowtype
from dbo. Hur_product_buy as Buy
INNER JOIN dbo. Yyd_users_reginfo as Reg on reg.id = Buy.userid) as Data
ORDER by bid_user_id, Createtime DESC

Use instance SQL for Union all

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.