MySql,替代在UNION

时间:2019-07-20 01:42:39

标签: mysql sql subquery union in-subquery

我已经解决了很长时间,所以我决定问一下在我的头部爆炸之前是否有人可以提出一些建议。

这是我正在运行的查询,它只是在子查询中多次重复同一子查询。我想看看我必须加快哪些替代方案。

到目前为止,我所能想到的就是运行一个初始查询,然后为第二个查询插入结果。

在此先感谢任何有时间的人。

SELECT t2.* FROM TABLEA as t2 where
t2.link_id in 
(
    select t4.LinkA as link_list from TABLEB as t4
    where t4.LinkB in (
        select t1.id from TABLEC as t1 where t1.number in
        (
            (select t2.number from TABLEC as t2 where t2.id in 
                (
                select t3.link_id from TABLEA as t3 where t3.an like "%20278%"
                )
            )
        )
    )
    union

    select t4.LinkB as link_list from TABLEB as t4
    where t4.LinkB in (
        select t1.id from TABLEC as t1 where t1.part_number in
        (
            (select t2.number from TABLEC as t2 where t2.id in 
                (
                select t3.link_id from TABLEA as t3 where t3.an like "%20278%"
                )
            )
        )
    )
    union


    select t4.LinkA as link_list from TABLEB as t4
    where t4.LinkA in (
        select t1.id from TABLEC as t1 where t1.number in
        (
            (select t2.number from TABLEC as t2 where t2.id in 
                (
                select t3.link_id from TABLEA as t3 where t3.an like "%20278%"
                )
            )
        )
    )
    union

    select t4.LinkB as link_idlist from TABLEB as t4
    where t4.LinkA in (
        select t1.id from TABLEC as t1 where t1.number in
        (
            (select t2.number from TABLEC as t2 where t2.id in 
                (
                select t3.link_id from TABLEA as t3 where t3.an like "%20278%"
                )
            )
        )
    )
)

0 个答案:

没有答案