我想要从第一个表中选择两个,具体取决于第二个表。
第一张表
ex_instagram_p:
id (int)
username (varchar)
cpc (int)
type (varchar)
active (int)
第二张表
exchanges
id (int)
user (varchar)
exid (int)
我想要的是什么:
从 ex_instagram_p 中选择值,并确保它不等于第二个表中的任何条目交换其中exchanges.user = $ username rows不包含ex_instagram_p。 id.on exchanges.id
让我清楚一下
例如表一是博客文章
因此用户将显示文章!=他的用户名和有效= 1并输入='“。跟随。”'
,第二个表是视图。
所以如果第二个表上有一个用户= $ username和exid = firsttable.id的条目
此条目已被该用户查看,我不希望他再次查看。
Actually i need if no entry on the exchanges table got the values of
user - exid
$username - i.id
if this doesn't exist is should continue
这是我创建的代码,但它不起作用
$prowz= mysql_query("SELECT i.*
FROM ex_instagram_p as i, exchanges as e
HAVING COUNT(e.user = '".$username." And e.exid = i.id) = 0
WHERE
AND i.type = '".follow."'
AND i.active=1
AND i.username != '".$username."'
ORDER BY i.cpc DESC
LIMIT 1;");
答案 0 :(得分:0)
$follow
应该是变量,或者只是字符串'follow'
。它是一个未定义的常数。
"SELECT i.* FROM ex_instagram_p i, exchanges e
WHERE i.id != e.exid
&& e.user = '$username'
&& i.type = '$follow'
&& i.active = 1
&& i.username != '$username'
ORDER BY i.cpc DESC LIMIT 1;"
答案 1 :(得分:-1)
许多WHERE条款,但它很简单..
SELECT i.*
FROM ex_instagram_p as i, exchanges as e
WHERE i.id != e.exid
AND e.user = '".$username."'
AND i.type = '".follow."'
AND i.active=1
AND i.username != '".$username."'
ORDER BY i.cpc DESC
LIMIT 1;