SQL - 连接多个选择/表

时间:2015-10-01 15:08:24

标签: sql join pervasive

我的第一个询问......

SELECT
    t1.a, t1.b, t1.c,
    t2.a, t2.b, t2.c

FROM t1

LEFT JOIN t2 ON t1.a = t2.a

WHERE t1.b = '000000'

AND LENGTH(t1.a) > '5'

AND t1.c <> 'Y';

我的第二个问题......

SELECT
    t1.a,
    t3.b as testMe

FROM t1

LEFT JOIN t3 ON t1.a = '0' + LEFT(t3.a, 5)

WHERE t1.a = '017941';

这两个查询本身都可以正常工作,但我需要将它们组合成一个结果集。值得注意的是,第二个查询中的where子句是出于测试目的,但是当我删除它时,整个事情就会崩溃。不确定这是否意味着我需要一些东西来过滤,或者它的超时?我使用的数据库是Pervasive。

我的查询失败......

SELECT
    t1.a, t1.b, t1.c,
    t2.a, t2.b, t2.c,
    t3.b as testMe

FROM t1

LEFT JOIN t2 ON t1.a = t2.a

LEFT JOIN t3 ON t1.a = '0' + LEFT(t3.a, 5)

WHERE t1.b = '000000'

AND LENGTH(t1.a) > '5'

AND t1.c <> 'Y';

我已经缩短了我的代码以更好地展示我的目标,但实际的代码可以在这里找到:http://codeshare.io/A2aB9

1 个答案:

答案 0 :(得分:0)

您可以尝试将这两个集合用作子选择语句并将它们连接在一起。我将两个查询之间的连接条件作为单独的列拉出,以便将java.lang.NullPointerException at com.android.tools.idea.configurations.ConfigurationMenuAction$PreviewAction.actionPerformed(ConfigurationMenuAction.java:269) at com.intellij.ui.popup.PopupFactoryImpl$ActionPopupStep$1.run(PopupFactoryImpl.java:746) at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311) at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:756) at java.awt.EventQueue.access$500(EventQueue.java:97) at java.awt.EventQueue$3.run(EventQueue.java:709) at java.awt.EventQueue$3.run(EventQueue.java:703) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76) at java.awt.EventQueue.dispatchEvent(EventQueue.java:726) at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:734) at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:569) at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:382) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93) at java.awt.EventDispatchThread.run(EventDispatchThread.java:82) 保留在结果集中。

testMe