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

node.js - How to mock a third-party api calls in the backend -

node.js - Why do I get "SOCKS connection failed. Connection not allowed by ruleset" for some .onion sites? -

matlab - 0-by-1 sym - What do I need to change in order to get proper symbolic results? -