比如有两个三个表
create table user
(
id INT(11) NOT NULL ,
uid INT(11) NOT NULL,
)
insert into user VALUES( '1','1')
insert into user VALUES( '2','2')
insert into user VALUES ( '3','3')create table test1
(
id INT(11) NOT NULL ,
uid INT(11) NOT NULL,
title varchar(20)
)create table test2
(
id INT(11) NOT NULL ,
uid INT(11) NOT NULL,
time INT
)
insert into test2 ( '1','1','13975204')
insert into test2 ( '2','2','13975238')
insert into test2 ( '3','3','13975562')create table test3
(
id INT(11) NOT NULL ,
uid INT(11) NOT NULL,
fid INT(11) NOT NULL
)
insert into test3 ( '2','1','2')
insert into test3 ( '3','1','3')以上uid fid 都是来自user中uid 的值
问题来了 请问如何查询才能得到如下效果
uid title time
1 13975204
2 13975238
3 13975562我的sql语句是这样的
SELECT t.uid,t.title,e.time FROM test1 t, test2 e LEFT JOIN test3 s ON t.uid=s.fid OR e.uid=s.fid WHERE s.uid=1 OR t.uid=1 OR e.uid=1因为test1表一条数据也没有所以这条语句就不能通过,请高手们快来看看吧
create table user
(
id INT(11) NOT NULL ,
uid INT(11) NOT NULL,
)
insert into user VALUES( '1','1')
insert into user VALUES( '2','2')
insert into user VALUES ( '3','3')create table test1
(
id INT(11) NOT NULL ,
uid INT(11) NOT NULL,
title varchar(20)
)create table test2
(
id INT(11) NOT NULL ,
uid INT(11) NOT NULL,
time INT
)
insert into test2 ( '1','1','13975204')
insert into test2 ( '2','2','13975238')
insert into test2 ( '3','3','13975562')create table test3
(
id INT(11) NOT NULL ,
uid INT(11) NOT NULL,
fid INT(11) NOT NULL
)
insert into test3 ( '2','1','2')
insert into test3 ( '3','1','3')以上uid fid 都是来自user中uid 的值
问题来了 请问如何查询才能得到如下效果
uid title time
1 13975204
2 13975238
3 13975562我的sql语句是这样的
SELECT t.uid,t.title,e.time FROM test1 t, test2 e LEFT JOIN test3 s ON t.uid=s.fid OR e.uid=s.fid WHERE s.uid=1 OR t.uid=1 OR e.uid=1因为test1表一条数据也没有所以这条语句就不能通过,请高手们快来看看吧
解决方案 »
- 问一个关于mysql里字段占的字节数的问题
- mySQL在主机为xp和vista双系统下的数据共享问题
- win7家庭版能装mysql吗?
- mssql to mysql
- 求一条删除几行数据的SQL语句。
- 如果数据在录入与输出的时候有单引号或双引号,需要做那些处理?
- 能不能用一条select语句统计出几个数据(不同条件下得出来的数据)
- 急!MySql有没有类似SqlServer sysobjects的系统表!
- mysql中有没有mssqlserver中的以下概念:rule(规则),procedure(存储过程),trigger(触发器)
- mysql
- 在MySQL的安装过程中出现安装的最后一步无法响应的问题解决
- 触发器如何触发一张表没有变动的数据?
上面的INSERT 语句由于复制粘贴所以搞错了 对应create语句下的insert 语句是针对相应表的
敬请包涵、、、
WHERE s.uid=1 OR t.uid=1 OR e.uid=1