我正在构建一个带有内部 SQLite DB 的 Android 应用程序。这是架构:
CREATE TABLE IF NOT EXISTS [tblImageVideoLink] (
[LinkID] INTEGER NOT NULL PRIMARY KEY,
[ImageID] INTEGER UNIQUE NOT NULL,
[VideoID] INTEGER NULL
);
CREATE TABLE IF NOT EXISTS [tblImages] (
[ID] INTEGER PRIMARY KEY NOT NULL,
[ImageName] VARCHAR(50) NOT NULL,
[ImageDescription] VARCHAR(100) NULL,
[Page] INTEGER NULL
);
CREATE TABLE IF NOT EXISTS [tblPages] (
[ID] INTEGER NOT NULL PRIMARY KEY,
[PageName] VARCHAR(30) NULL
);
CREATE TABLE IF NOT EXISTS [tblVideos] (
[ID] INTEGER NOT NULL PRIMARY KEY,
[VideoName] VARCHAR(150) NOT NULL,
[VideoDescription] VARCHAR(100) NULL,
[VideoType] VARCHAR(10) NULL
);
CREATE INDEX IF NOT EXISTS [IDX_TBLIMAGEVIDEOLINK_IMAGEID] ON [tblImageVideoLink](
[ImageID] DESC,
[VideoID] DESC
);
CREATE INDEX IF NOT EXISTS [IDX_TBLIMAGES_PAGE] ON [tblImages](
[Page] DESC
);
这是我在表格中的相关数据:
INSERT INTO tblImages (ID, ImageName, Page) VALUES (1, 'Beach.jpg', 1);
INSERT INTO tblImages (ID, ImageName, Page) VALUES (2, 'Bowling.jpg', 1);
INSERT INTO tblImages (ID, ImageName, Page) VALUES (3, 'Car.jpg', 1);
INSERT INTO tblVideos (ID, VideoName) VALUES (2, 'Bowling.3gp');
INSERT INTO tblVideos (ID, VideoName) VALUES (3, 'Car.3gp');
INSERT INTO tblImageVideoLink (LinkID, ImageID, VideoID) VALUES (1, 2, 2);
INSERT INTO tblImageVideoLink (LinkID, ImageID, VideoID) VALUES (2, 3, 3);
INSERT INTO tblPages (ID, PageName) VALUES (1, 'Misc');
我正在尝试运行此查询以获取具有特定页面的所有图像及其相关视频:
SELECT DISTINCT I.ID AS 'Image ID', I.ImageName, V.ID AS 'Video ID', V.VideoName
FROM tblImages I
LEFT JOIN tblImageVideoLink L ON L.VideoID=V.ID
LEFT JOIN tblVideos V ON L.ImageID=I.ID
WHERE I.Page=1;
当我在SQLite Administrator中对其进行测试时,我得到了所需的结果集,即:
当我在 App (或SQLiteSpy)中测试它时,我得到了不同的结果集:
我已经尝试了我所知道的一切,包括 GROUP BY、删除 DISTINCT、不同的 JOIN 类型等。
顺便说一句,SQLiteSpy 在底部写:SQLite 3.7.8,而 SQLite Administrator 写 SQLite 3.5.1。我不知道这是否重要。
请帮助,并请解释为什么两个 SQLite 工具之间存在差异......