UNION子查询中的两个表

时间:2016-06-02 17:55:57

标签: mysql subquery union

我在子查询中尝试UNION两个表,但显然这是不允许的?我的查询的简化版本是:

SELECT *
FROM user, organization
WHERE user.id NOT IN (
    (SELECT distinct user_id FROM web_request)
    UNION
    (SELECT distinct user_id from user_milestone)
)
AND user.organization_id = organization.id

我的问题是:解决MySQL这个缺点的最佳方法是什么?

2 个答案:

答案 0 :(得分:3)

SELECT u.*, o.*
FROM `user` u
INNER JOIN organization o
ON u.organization_id = o.id
WHERE u.id NOT IN(
    SELECT distinct user_id FROM web_request
    UNION
    SELECT distinct user_id from user_milestone
)

答案 1 :(得分:1)

试试这个

import re
import urllib
import datetime
from bs4 import BeautifulSoup

link = "https://www.gpo.gov/fdsys/granule/FR-2016-06-02/2016-12978/mods.xml"
italink = urllib.urlopen(link).read()
soup = BeautifulSoup(italink)
print soup