在 iPhone 上加入 SQLITE
我有一个 SQLite 请求要做,但我不知道该怎么做。
这是:
SELECT videoid,inappid FROM store,video
WHERE store.paid='1' AND store.checked='1'
AND video.inappid=store.inappid AND video.download =='0'
ORDER BY video.inappid DESC,video.videoid;
--> SQL ERROR 答案:DB 错误:1 “不明确的列名:inappid”
我解释一下:store 和 video 是 2 个表。 在商店中,有“inappid”(com.mysite.myapp.000) 引用的产品。 'inappid' 列名是表中的键并且是唯一的。已付款和已检查只是存储表中的布尔值。
在视频中,有...视频,每个视频都有一个唯一的密钥“videoid”。引用存储表中 inappid 的“inappid”列。
所以我的请求是:选择商店表中元素的所有 inappid 参数,其中付费和检查为 TRUE,并选择视频表中带有此 inappid 的视频的所有 videoid,其中该视频尚未下载。
我知道我必须使用 JOIN 和 ON 元素,但我不知道如何
请帮助 Oo。
I have a SQLite request to do and I don't know how to do it.
Here it is :
SELECT videoid,inappid FROM store,video
WHERE store.paid='1' AND store.checked='1'
AND video.inappid=store.inappid AND video.download =='0'
ORDER BY video.inappid DESC,video.videoid;
--> SQL ERROR answer : DB Error: 1 "ambiguous column name: inappid"
I explain : store and video are 2 tables.
in store, there is product referenced by 'inappid' (com.mysite.myapp.000). 'inappid' column name is the key in the table and is unique. paid and checked are just boolean in the store table.
in video, there is... video and each video has a unique key 'videoid'. an 'inappid' column that refers to the inappid in the store table.
So my request was : select me all the inappid params of element in the store table where paid and checked are TRUE and SELECT me all the videoid of video with this inappid in the video table WHERE this video is not already downloaded.
I know I must use JOIN and ON element but I don't know how
please help Oo.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由于两个表都包含一列
inappid
,因此当您说SELECT videoid,inappid FROM ...
时,它不知道您要返回哪一列。一个简单的解决方案是明确选择一个:
SELECT videoid,video.inappid FROM ...
另一种解决方案是使用 JOIN 和 USING 进行连接,在这种情况下,它将知道“inappid”两个表中的列是等效的:
SELECT videoid,inappid FROM store JOIN video USING(inappid) WHERE store.paid='1' AND store.checked='1' AND video.download =='0' ORDER BY video .inappid DESC,video.videoid
Because both tables contain a column
inappid
, it doesn't know which one you are wanting to return when you saySELECT videoid,inappid FROM ...
.One simple solution is to just explicitly pick one:
SELECT videoid,video.inappid FROM ...
Another solution is to do your join using JOIN and USING, in which case it will know that the "inappid" columns in both tables are equivalent:
SELECT videoid,inappid FROM store JOIN video USING(inappid) WHERE store.paid='1' AND store.checked='1' AND video.download =='0' ORDER BY video.inappid DESC,video.videoid
或许?
Maybe?