1

我正在开发一个应用程序,我在其中定义了下表。

storytags
id  cover_title                   user_id
1  love happens two times?         1
2  revolution 2020                 2
3  wings of fire                   3
4  night at the call centre        4

storytag_invitations
id  storytag_id  user_id
1      1            1
2      2            2
3      3            3
4      4            4
users
id  name
1  suhas
2  sangu
3  praveen
4  sangamesh

我想为用户 3 获取 storytag_invitations.user_id != storytags.user_id 和 storytag_invitations.storytag_id != storytags.id 的故事标签

我尝试了以下查询

select storytags.cover_title
from storytag_invitations
join storytags
on storytags.id != storytag_invitations.storytag_id and storytags.user_id !=  storytag_invitations.user_id
where storytag_invitations.user_id = 3

但我得到重复的行。请提出一些解决方案。已经两天了,我正在尝试这个。工作会更受欢迎。

4

3 回答 3

2
//if you are using codeigniter then try this
$this->db->select("table1.column1,table1.column2,table2.column");
$this->db->join("table2","table1.column = table2.column");
$resultset=$this->db->get();
于 2013-07-19T05:28:47.427 回答
1

试试它是否适合你:

$sql    = "select storytags.cover_title from storytags, storytag_invitations where ( storytags.id != storytag_invitations.storytag_id and storytags.user_id !=  storytag_invitations.user_id ) and storytag_invitations.user_id = 3";
$rs     = $this->db->query($sql);
于 2013-07-16T11:03:47.030 回答
1

当我使用 from 时,您的 sql 对我有用:

select s.cover_title
  from storytag_invitations si, storytags s
 where s.id != si.storytag_id
   and s.user_id != si.user_id
   and si.user_id = 3

你可以在这里查看:http ://sqlfiddle.com/#!4/ecd77/4

于 2013-07-16T11:13:42.187 回答