SELECT count( t1.id ) , t2.special_value
FROM table_1 AS t1, table_2 AS t2
WHERE t1.`group` = 'val'
AND t2.code = 'val'
returns
count - normal value
special_value - NULL
but
SELECT t2.special_value
FROM table_2 AS t2
WHERE t2.code = 'val'
returns
special_value - another normal value
why first query works wrong?..
currently, i need
(count( t1.id ) + t2.special_value)
This is why you should never use SQL’89 implicit join syntax.
You have no join condition resulting in a cross join.
Rewrite the query using explicit join syntax:
I don’t know how table t1 and t2 are linked, so you’ll have to tweak this a bit, but that’s how it supposed to work.
And please never ever use implicit
wherejoins again.Remarks
I’m wondering what
p.`group`andpp.codeare, but I’m guessing you meant to writet1.`group`andt2.codeYou only need to escape fields and tablenames in
`backticks if they are reserved words.Personally all those backticks make me dizzy, but that’s just me.