简体   繁体   English

android.database.sqlite.SQLiteException:靠近“UNION”:语法错误

[英]android.database.sqlite.SQLiteException: near "UNION": syntax error

I am using SQLite database for android我正在为 android 使用 SQLite 数据库

SQLite query SQLite 查询

SELECT t1.id,t1.name, t1.email FROM ((SELECT id,first_name as 
name,email FROM single_general where unique_code='UD') 
UNION ALL (SELECT name,email FROM school where 
unique_code='UD') ) t1

The SELECT syntax does not allow parentheses about the compound queries. SELECT 语法不允许关于复合查询的括号。 Remove them, so that only the parentheses around the subquery are left:删除它们,以便只留下子查询周围的括号:

SELECT id, name, email
FROM (SELECT id, first_name AS name, email
      FROM single_general
      WHERE unique_code = 'UD'
      UNION ALL
      SELECT 0, name, email
      FROM school
      WHERE unique_code = 'UD');

The number of columns in all of queries in the union must be the same.联合中所有查询的列数必须相同。 There is no ID column in the 'school' table query. 'school' 表查询中没有 ID 列。 Can you get an ID field from 'school'?.您可以从“学校”获取 ID 字段吗? Try the following code creates a 0 filled field for ID in the second query:尝试以下代码为第二个查询中的 ID 创建一个 0 填充字段:

SELECT t1.id,t1.name, t1.email FROM ((SELECT id,first_name as 
name,email FROM single_general where unique_code='UD') 
UNION ALL (SELECT 0 as id,name,email FROM `school` where 
unique_code='UD') ) t1

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 android.database.sqlite.SQLiteException:靠近“。”:语法错误(代码1): - android.database.sqlite.SQLiteException: near “.”: syntax error (code 1): , 原因:android.database.sqlite.SQLiteException:附近“”:语法错误(代码1): - Caused by: android.database.sqlite.SQLiteException: near “”: syntax error (code 1): android.database.sqlite.SQLiteException:“;”附近:语法错误(代码1) - android.database.sqlite.SQLiteException: near “;”: syntax error (code 1) Android Studio 创建数据库错误(android.database.sqlite.SQLiteException: near "and": syntax error (code 1): )详解 - Android Studio Create Database error (android.database.sqlite.SQLiteException: near "and": syntax error (code 1): ) Detailed Analysis android.database.sqlite.SQLiteException:“WHERE”附近:语法错误(Sqlite 代码 1) - android.database.sqlite.SQLiteException: near “WHERE”: syntax error (Sqlite code 1) 错误:引起:android.database.sqlite.SQLiteException:near“add”:语法错误(代码1): - Error: Caused by: android.database.sqlite.SQLiteException: near “add”: syntax error (code 1): 引起:android.database.sqlite.SQLiteException:near“”:语法错误(代码1):,同时编译: - Caused by: android.database.sqlite.SQLiteException: near “”: syntax error (code 1): , while compiling: android.database.sqlite.SQLiteException:靠近“ 1”:语法错误(代码1): - android.database.sqlite.SQLiteException: near “1”: syntax error (code 1): , while compiling android.database.sqlite.SQLiteException:靠近“SET” - android.database.sqlite.SQLiteException: Near "SET" 造成原因:android.database.sqlite.SQLiteException:“文本”附近:语法错误(代码1): - Caused by: android.database.sqlite.SQLiteException: near “text”: syntax error (code 1):
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM