Sub query count in mysql -


i have following query gets me data i'm after...

$query  = @"select table1.user_id, table1.col8, table2.col5, user_tokens.expiry table1  inner join table2 on table1.user_id=table2.user_id inner join user_tokens on user_tokens.user_id=table1.user_id  table1.col2 = '{$username}'"; 

i've been playing around give me data without second query. data want row count table - table10 (that has user_id column) user_id columns match.

so like...

,

(select count(*) table) userdatacount 

which giving me row count whole table, not rows have same user_id table1

i figured inner joins i've done count table10 rows user_id columns match rest of query, , different ways i've tried of joining table10, or using where table10.user_id = table1.user_id failing.

is there simple way this, or need 2 separate queries?

select  table1.user_id,  table1.col8,  table2.col5,  user_tokens.expiry,  (select count(*)      table         table.user_id=table1.user_id) ucount      table1      inner join table2     on table1.user_id=table2.user_id     inner join user_tokens     on user_tokens.user_id=table1.user_id      table1.col2 = '{$username}'"; 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -