-1

I have two tables one named logins and one named members.

Both members and logins have "Name" field. This is the primary key.

Members includes information for accounts including the field "Rank" logins includes information on last login with a unix time stamp on the field "time"

I need to run a query for the members table that is Rank > 1 but I also need to make sure that the "time" field is more than 1391212800 from the logins table.

How would I do this?

  • 1
    To the "unclear" or "lacks info" close voters: this is a common SQL beginner's question. For an intermediate level SQL programmer, it is very clear what is being asked. The clarity of the question is further supported by the two identical answers. – Andomar Feb 08 '14 at 12:32
  • @Andomar, the votes will be because OP has shown no research effort or attempt to solve the problem. – OGHaza Feb 08 '14 at 12:38
  • @OGHaza: I don't think this question will be improved by including the result of Google queries (which is what "research" comes down to in this context.) And if you don't know where to start, you can't produce failed attempts. – Andomar Feb 08 '14 at 12:45
  • @Andomar, don't know where to start? How about typing this exact question title into google and clicking the [1st SO result](http://stackoverflow.com/questions/12475850/how-can-an-sql-query-return-data-from-multiple-tables). – OGHaza Feb 08 '14 at 12:59
  • 1
    @OGHaza: That SO result is like a Wikipedia article. To use a hyperbole, you could point any poster at the SQL specification, and say "it's all in there". I think that's very different from Q&A learning. – Andomar Feb 08 '14 at 13:04
  • @Andomar You're right that is hyperbole. If you honestly think every time a beginner needs to "query from multiple tables" they should be asking a question on SO then fair enough, I agree to disagree. – OGHaza Feb 08 '14 at 13:18
  • This question should remain closed because it is a duplicate of the question that @OGHaza turned up: [How can an SQL query return data from multiple tables](http://stackoverflow.com/questions/12475850/how-can-an-sql-query-return-data-from-multiple-tables) – Wayne Conrad Feb 08 '14 at 13:49

2 Answers2

0
 select m.name , m.rank from logins l
 inner join members m
 on l.mame = m.name
 WHERE time >= 1391212800
 and m.rank > 1
echo_Me
  • 37,078
  • 5
  • 58
  • 78
0

You can use a join to build a recordset from two distinct tables. The on clause allows you to specify the relation between the two tables.

Finally, you can apply a where clause to the new recordset that can refer to fields from both the original tables.

select  *
from    Members m
join    Logins l
on      l.name = m.name
where   m.Rank > 1
        and l.time > 1391212800
Andomar
  • 232,371
  • 49
  • 380
  • 404