sql - Select all values from first table and ONLY first value from second table -


enter image description here

i want select values users , min of dateused in code table. how can that?

i've tried this:

    select u.firstname, u.lastname, u.fbid, q.dateused, u.codesleft   users u   inner join code q on  u.id = q.userid 

but it's selecting values code , users tables.

p.s. adding distinct has no effect

adding distinct has no effect

as rule of thumb, distinct helps single-column selects. multiple columns need go "big guns" - group by clause.

in order work need make sure each item select either group by column, or has suitable aggregation function:

select u.firstname, u.lastname, u.fbid, min(q.dateused) dateused, u.codesleft users u inner join code q on u.id = q.userid group u.firstname, u.lastname, u.fbid, u.codesleft 

Comments

Popular posts from this blog

java - Could not locate OpenAL library -

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

sorting - opencl Bitonic sort with 64 bits keys -