sqlite用一张表的数据更新另一张表 5
类似于:SQLserver:updateaseta.id=b.idfromtable_1ainnerjointable_2ona.name=b.name的写法么SQLse...
类似于:SQL server : update a set a.id =b.id from table_1 a inner join table_2 on a.name=b.name
的写法么
SQL server : update a set a.id =b.id from table_1 a inner join table_2 b on a.name=b.name
改下这个Sql哈,,但是为什么不能在sqlite里执行呢。。求大神指点 展开
的写法么
SQL server : update a set a.id =b.id from table_1 a inner join table_2 b on a.name=b.name
改下这个Sql哈,,但是为什么不能在sqlite里执行呢。。求大神指点 展开
2个回答
展开全部
Update ...From(Cross Join in Update):Sqlite 不支持类似
“UPDATE tbl1 SET col2 = tbl2.col2
FROM table1 tbl1 INNER JOIN table2 tbl2 ON tbl1.col1 = tbl2.col1”
的update,替代的解决办法是:
UPDATE table1 SET col2 = (select col2 from table2 where table2.col1=table1.col1 limit 1)
where exists(select * from table2 where table2.col1=table1.col1);
“UPDATE tbl1 SET col2 = tbl2.col2
FROM table1 tbl1 INNER JOIN table2 tbl2 ON tbl1.col1 = tbl2.col1”
的update,替代的解决办法是:
UPDATE table1 SET col2 = (select col2 from table2 where table2.col1=table1.col1 limit 1)
where exists(select * from table2 where table2.col1=table1.col1);
2015-03-25
展开全部
$ sqlite3
SQLite version 3.7.7 2011-06-23 19:49:22
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> create table users
...> (
...> u_id int,
...> u_user varchar(32),
...> u_gid varchar(32)
...> );
sqlite>
sqlite> create table groups
...> (
...> g_id int,
...> g_name varchar(32),
...> g_pow varchar(32)
...> );
sqlite>
sqlite> create table power
...> (
...> p_id int,
...> p_name varchar(32)
...> );
sqlite>
sqlite> insert into users values (1, 'admin', '1,2');
sqlite>
sqlite> insert into groups values (1, '超级', '1,3');
sqlite> insert into groups values (2, '低级', '2');
sqlite>
sqlite> insert into power values (1, '吃');
sqlite> insert into power values (2, '喝');
sqlite> insert into power values (3, '玩');
sqlite>
sqlite> .head on
sqlite>
sqlite> select *
...> from users, groups, power
...> where 1=1
...> and like(
...> '%,'||g_id||',%',
...> ','||u_gid||','
...> )
...> and like(
...> '%,'||p_id||',%',
...> ','||g_pow||','
...> )
...> ;
u_id|u_user|u_gid|g_id|g_name|g_pow|p_id|p_name
1|admin|1,2|1|超级|1,3|1|吃
1|admin|1,2|1|超级|1,3|3|玩
1|admin|1,2|2|低级|2|2|喝
sqlite>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询