rockmerockme
rockmerockme

Reputation: 129

Nested select in mysql_query

mysql_query("SELECT a.guessNum FROM (SELECT * FROM PeerPrediction1 WHERE taskid=$taskid INNER JOIN UserData On username) a WHERE spanflag=0");

I have this query but it does not work. PeerPrediction1 is a table with schema: username, taskid... Userdata: username, guessNum,spanfalg I followed this link, but still something wrong, could anybody help? Nested select statement in SQL Server

Upvotes: 0

Views: 338

Answers (2)

Fabio
Fabio

Reputation: 28

I think you miss-match inner join on username. See: http://www.w3schools.com/sql/sql_join_inner.asp

Upvotes: 1

Abhik Chakraborty
Abhik Chakraborty

Reputation: 44844

The query syntax is not correct, and you do not need sub-query for this , you can just use the join to get the data as

select
u.guessNum from PeerPrediction1 a
join UserData u on u.username = a.username
where 
a.taskid = ? --- $taskid
and u.spanflag = 0 

Upvotes: 1

Related Questions