繁体   English   中英

mysql查询取决于其他表

[英]mysql query depending on other table

我要根据第二张表从第一张表中选择两个

第一张桌子

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行在exchanges.id上不包含ex_instagram_p.id

让我清除它

例如表一是博客文章

因此用户将显示文章!=他的用户名,active = 1并输入='“。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;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM