如何将2个SQL语句组合到一个语句中

时间:2016-06-08 16:59:35

标签: mysql sql

想象一下,我有一个表格,其中包含一个人的信息(每人一行),我们可以将其称为TableA,现在我想让所有有债务的人在TableB和还可以在TableC中按月支付。

现在用2个命令完成这个很简单,很简单:

SELECT * 
  FROM TableA 
 WHERE ID IN (SELECT ID 
                FROM TABLEB 
               WHERE Header1=false);

SELECT * 
  FROM TableA 
 WHERE ID IN (SELECT ID 
                FROM TABLEC 
               WHERE Header2=false);

但是我不想制作2个单独的命令来返回2个单独的数据表,是不是可以将它们连接在一起并将它们全部合并而不重复?类似的东西:

SELECT * 
  FROM TableA 
 WHERE ID IN (SELECT ID 
                FROM TABLEB 
               WHERE Header1=false 
                 AND 
              SELECT ID 
                FROM TABLEC 
               WHERE Header2=false);

如果可以,那么正确的语法是什么?

1 个答案:

答案 0 :(得分:2)

为什么不使用<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd"> <plist version="0.9"> <dict> <key>CFBundleName</key> <string>gna</string> <key>CFBundleExecutable</key> <string>JavaApplicationStub</string> <key>CFBundleIconFile</key> <string>app.icns</string> <key>CFBundleInfoDictionaryVersion</key> <string>6.0</string> <key>CFBundlePackageType</key> <string>APPL</string> <key>CFBundleSignature</key> <string>????</string> <key>CFBundleIdentifier</key> <string>com.install4j.7878-5124-9390-0704.96</string> <key>CFBundleVersion</key> <string>8.7.1.1</string> <key>CFBundleShortVersionString</key> <string>8.7.1.1</string> <key>CFBundleGetInfoString</key> <string>8.7.1.1</string> <key>CFBundleDevelopmentRegion</key> <string>en</string> <key>CFBundleAllowMixedLocalizations</key> <true/> <key>NSHighResolutionCapable</key> <true/> <!-- I4J_INSERT_DOCTYPE --> <key>i4j.baseDir</key> <string>$APP_PACKAGE/../</string> <key>LSMinimumSystemVersion</key> <string>10.7.3</string> <key>i4j.appId</key> <string>7878-5124-9390-0704</string> <key>i4j.allowPassthrough</key> <true/> <key>i4j.minVersion</key> <string>1.7</string> <key>i4j.maxVersion</key> <string>1.7</string> <key>i4j.vmIdPrefix</key> <string></string> <key>JavaVM</key> <dict> <key>MainClass</key> <string>com.install4j.runtime.launcher.MacLauncher</string> <key>VMOptionArray</key> <array> <string>-Dfile.encoding=UTF-8</string> <string>-Diogma.home=$APP_PACKAGE/..</string> <string>-Diogma.user.home=$APP_PACKAGE/..</string> <string>-Diogma.user.externals=$APP_PACKAGE/..</string> <string>-Diogma.user.data=$APP_PACKAGE/..</string> <string>-Diogma.licenser=default</string> <string>-Dlog4j.debug</string> <string>-Dlog4j.configuration=iogma/platform/log4j.properties</string> <string>-Dswing.defaultlaf=net.infonode.gui.laf.InfoNodeLookAndFeel</string> <string>-Duser.language=en</string> <string>-Diogma.application.name=GNA</string> <string>-Diogmadatabase=false</string> <string>-Dinstall4j.launcherId=96</string> <string>-Dinstall4j.swt=false</string> <string>-Djava.library.path=$APP_PACKAGE/../Externals/Ports/x86_64-darwin/lib</string> <string>-Dexe4j.moduleName=$APP_PACKAGE</string> </array> <key>OptionsFile</key> <string>$APP_PACKAGE/Contents/vmoptions.txt</string> <key>ArgumentArray</key> <array> </array> <key>SplashFile</key> <string>$APP_PACKAGE/../.install4j/s_1qq6wu9.png</string> <key>JVMVersion</key> <string>1.4+</string> <key>ClassPath</key> <string>$APP_PACKAGE/../.install4j/i4jruntime.jar:$APP_PACKAGE/../bin/*:$APP_PACKAGE/../GNA/bin/*:$APP_PACKAGE/../plugins/iogma.core.platform/bin/*</string><!-- I4J_INSERT_CLASSPATH --> </dict> </dict> </plist>

UNION