mysql多表联结问题

来源:百度知道 编辑:UC知道 时间:2024/06/25 22:42:22
table1
id statu(状态)
1 OK
2 OK
3 NO

table2
id title
1 网络游戏
2 电子游戏
3 书籍

求:写出Mysql命令,取出“正常”的,title中含有“游戏”的ID。

我写的在这里:

select id from table1 inner join table2 on table1、id=table2.id
where status=OK and title like ‘%游戏%’

对吗。不对的话请高手写个参考答案。

select table1.id from table1 ,table2 where table1.id=table2.id
and table1.status='OK' and table2.title like '%游戏%'


select table1.id from table1 inner join table2 on table1.id=table2.id
where table1.status='OK' and table2.title like '%游戏%'

你的错误在于,OK是字符串,必须用引号引起来,标点符号混淆,其实该用英文的,以上这两个都能正常运行 ,还有,你那个字段叫什么?status还是statu?你两次写的不一样呢?

Select id, title From table1 Inner Join table2 On(table1.id=table2.id) Where status='OK' And title Like '%游戏%'
还有一种简单写法
Select id, title From table1 Inner Join table2 Using(id) Where status='OK' And title Like '%游戏%'
你的table1、id是中文的顿号,不是英文的点

OK是字符串,需要用引号引起来
其他的都很对