I want to select entries from the first n groups. My data is as follows:
Table "runner":
id gid status rtime --------------------------- 100 5550 1 2016-08-19 200 5550 2 2016-08-22 300 5550 1 2016-08-30 100 6050 3 2016-09-01 200 6050 1 2016-09-02 100 6250 1 2016-09-11 200 6250 1 2016-09-15 300 6250 3 2016-09-19
Table 'static'
id description env ------------------------------- 100 something 1 somewhere 1 200 something 2 somewhere 2 300 something 3 somewhere 3
The device identifier (id) is unique within the group, but not unique in its column, because the group instance is generated regularly. A group identifier (gid) is assigned to each module, but is not generated in more than one instance.
Now combining tables and selecting everything or a filter by a specific value is easy, but how can I select all the records, for example, the first two groups without directly accessing the group identifiers? Expected Result:
id gid description status rtime -------------------------------------- 300 6250 something 2 3 2016-09-19 200 6250 something 1 1 2016-09-15 100 6250 something 3 1 2016-09-11 200 6050 something 2 1 2016-09-02 100 6050 something 1 3 2016-09-01
Additional question: when I filter for a timeframe, for example:
[...] WHERE runner.rtime BETWEEN '2016-08-25' AND '2016-09-16'
Is there an easy way to ensure that groups are not cut off, but are either displayed with all their records or not at all?
source share