我有两个,我想从第一个表中选择取决于第二个表。
第一个表ex_instagram_p:
id (int)
username (varchar)
cpc (int)
type (varchar)
active (int)
第二个表
exchanges
id (int)
user (varchar)
exid (int)
我想要什么:
select values from ex_instagram_p并确保它不等于第二个表exchanges中的任何条目。user = $username rows不包含ex_instagram_p。exchange . Id
让我把它清除
例如,表1用于博客文章
所以用户将显示文章!=他的用户名和active = 1和type ='".follow。"
,第二个表是视图。
所以如果在第二个表上有一个user = $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;");
$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;"
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;