sql - Select all values from first table and ONLY first value from second table -
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 select
s. 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
Post a Comment