English 中文(简体)
MYSQL 替代条款
原标题:MYSQL Subselect in where clause

我打破了我在这个简单的法典和平上的头脑,而这种和平却不希望工作,我只能想到任何其他解决办法。

请帮助它开展工作吗?

SELECT chart FROM chart WHERE (select count(user_id) FROM users join charts ON
user_id=charts.UID and charts.chart=chart WHERE INET_NTOA(user_ip)= 127.0.0.1 )=0;

以下各栏有3个表格:

chart(
chart int(5)
);

charts(
UID int(11),
chart int(5)
);

`users` (
`user_id` int(11),
`user_ip` int(10)
);

要点是,应从首选的图表栏改为图表。 图=图表,但次位数最终与本身比较,即海图=chart,总是真实。

我知道它赢得了这样的工作,但我确实想不到任何其他方式。 难道对我想要做的事情没有任何办法?

EDIT 1: Basically I need a reverse selection:

  select chart.chart from chart join charts on chart.chart=charts.chart join users
  on user_id=charts.UID and INET_NTOA(user_ip)= 127.0.0.1 ;

This query returns charts that are tagged by user with given ip, eg: 1, 4,5, 9. But I need to select the ones that are not tagged instead, that is: 2,3,6,7,8,10 and so on...

EDIT 2: I m looking for some sort of negative join now. I think this would do, but I m clueless how to use it. Meanwhile making some research...

最佳回答

Try:

SELECT c.chart FROM chart c
LEFT JOIN
( SELECT cn.chart FROM chart cn
  JOIN charts cs ON cn.chart = cs.chart
  JOIN users u ON u.user_id = cs.UID
  WHERE user_ip = 2130706433 ) charts_localhost
ON c.chart = charts_localhost.chart
WHERE charts_localhost.chart IS NULL

请注意,不使用<代码>INET_NTOA(用户_ip)=127.0.0.1,更便于使用

user_ip = 2130706433, which is Equal but also indexair.

问题回答

你们是否利用他人审判?

select a.chart from chart a where (select count(user_id) from users join charts on user_id=charts.UID and charts.chart=a.chart where INET_NTOA(user_ip)= 127.0.0.1 )=0;

我不知道它是否在教育、青年和体育部工作,但我认为它将在体育和体育部和Oracle工作。

I guess it s a naming problem... Try doing this :

SELECT c.chart FROM chart c
WHERE (
    SELECT COUNT(u.user_id) FROM users u
    INNER JOIN charts ch
     ON u.user_id = ch.UID 
     AND ch.chart = c.chart
    WHERE INET_NTOA(user_ip)= 127.0.0.1 
       ) = 0;

您可使用一个特定条款进行过滤:

SELECT TS.*, T.* 
FROM tbl_teams as T
LEFT JOIN tbl_teamstats TS 
    ON TS.tbl_teams_id = T.id
WHERE 
TS.id = (
        SELECT TS.id FROM tbl_teamstats TS 
        WHERE TS.tbl_teams_id = T.id
        ORDER BY TS.id DESC
        LIMIT 1
    ) 




相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签