我如何在不使用联接的情况下重写查询 [英] How could I rewrite a query without using joins

查看:54
本文介绍了我如何在不使用联接的情况下重写查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如果不使用任何联接将如何编写此查询.我一直在尝试找出联接不可行或无法使用(无法使用)的情况.

I would like to know how this query would be written if no joins were used. I been trying to figure it out for cases where joins aren't viable or can't be used(aren't available).

SELECT
    *
FROM
(
    table1
INNER JOIN
    table2
ON
    table1.id = table2.id
)
INNER JOIN
    table3
ON
(
    table1.id2 = table3.id2
)
AND
(
    table1.id3 = table3.id3
)
WHERE
    table1.id = 1

我不能使用联接的原因是因为应用程序使用HQL而不是标准SQL,并且HQL使得联接非常困难.

The reason I can't use joins is because the application uses HQL as opposed to standard SQL and HQL makes joins incredibly difficult to do.

推荐答案

如果不以一种或另一种方式联接它们,就不可能从两个不同的表中提取数据.您正在使用JOIN语句,但是可以通过将其放置在where子句中来实现相同的目的,例如:

It is impossible to extract data from two different tables without joining them in one way or another. You are using a JOIN statement BUT you can achieve the same thing by placing it in the where clause for example:

SELECT * FROM table1, table2 WHERE table1.id = table2.id AND ...

这篇关于我如何在不使用联接的情况下重写查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆