SQLite不支援的SQL語法總結

2021-05-24 10:04:26 字數 1613 閱讀 7679

1 top

這是乙個大家經常問到的問題,例如在sqlserver中可以使用如下語句來取得記錄集中的前十條記錄:

select top 10 * from [index] order by indexid desc;

但是這條sql語句在sqlite中是無法執行的,應該改為:

select * from [index] order by indexid desc limit 0,10;

其中limit 0,10表示從第0條記錄開始,往後一共讀取10條

2建立檢視(create view)

sqlite

在建立多表檢視的時候有乙個bug,問題如下:

create view watch_single as select distinct watch_item.[watchid],watch_item.[itemid] from watch_item;

上面這條sql語句執行後會顯示成功,但是實際上除了

select count(*) from [watch_single ] where watch_ single.watchid = 1;

能執行之外是無法執行其他任何語句的。其原因在於建立檢視的時候指定了字段所在的表名,而sqlite並不能正確地識別它。所以上面的建立語句要改為:

create view watch_single as select distinct [watchid],[itemid] from watch_item;

但是隨之而來的問題是如果是多表的檢視,且表間有重名字段的時候該怎麼辦?

3 count(distinct column)(我自己試驗貌似不存在這樣的問題)

sqlite

在執行如下語句的時候會報錯:

select count(distinct watchid) from [watch_item] where watch_item.watchid = 1;

其原因是sqlite的所有內建函式都不支援distinct限定,所以如果要統計不重複的記錄數的時候會出現一些麻煩。比較可行的做法是先建立乙個不重複的記錄表的檢視,然後再對該檢視進行計數。

4外連線

雖然sqlite官方已經聲稱left outer join

已經實現,但還沒有right outer join 和full outer join。但是實際測試表明似乎並不能夠正常的工作。以下三條語句在執行的時候均會報錯:

select tags.[tagid] from [tags],[tag_rss] where tags.[tagid] = tag_rss.[tagid](*);

select tags.[tagid] from [tags],[tag_rss] where left outer join tag_rss.[tagid] = tags.[tagid];

select tags.[tagid] from [tags],[tag_rss] where left join tag_rss.[tagid] = tags.[tagid];

此外經過測試用 號代替*號也是不可行的。

SQLite不支援的SQL語法總結

1 top 這是乙個大家經常問到的問題,例如在sqlserver中可以使用如下語句來取得記錄集中的前十條記錄 select top 10 from index order by indexid desc 但是這條sql語句在sqlite中是無法執行的,應該改為 select from index o...

SQLite不支援的SQL語法總結

1 top select top 10 from index order by indexid desc 但是這條sql語句在sqlite中是無法執行的,應該改為 select from index order by indexid desc limit 0,10 其中limit 0,10表示從第0...

SQLite不支援的SQL特性

sqlite 不支援的sql 特性 相對於試圖列出sqlite 支援的所有sql92 特性,只列出不支援的部分要簡單得多。下面顯示的就是sqlite 所不支援的sql92 特性。這個列表的順序關係到何時乙個特性可能被加入到sqlite 接近列表頂部的特性更可能在不遠的將來加入。接近列表底部的特性尚且...