Skip to content

ORDER BY and GROUP BY of UNIONs #83

@hiFloh

Description

@hiFloh

I already described by situation in issue #81.
but the Problem is now different.

How do i apply GROUP BY and ``ORDER BY``` to the union?

// curent working code missing ORDER BY
SQLPP_CREATE_NAME_TAG(timestamp);

(int id){

auto position=select(pos.ts.as(timestamp),pos.lon.as(sqlpp::alias::a),pos.lat.as(sqlpp::alias::b),sqlpp::value(std::optional<int>{}).as(sqlpp::alias::a)).where(pos.id==id);
auto sensor1= select(spec.ts.as(timestamp),sqlpp::value(std::optional<float>{}).as(sqlpp::alias::a),sqlpp::value(std::optional<float>{}).as(sqlpp::alias::b),spec.content.as(sqlpp::alias::c).where((spec.id==id)&&spec.type=="sensor1"))
db(position.union_distinct(sensor1));
}

I would expect the following code to produce the wanted sql statement. But i get the error has no member order_by

position.union_distinct(sensor1).order_by(timestamp);

Florian

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions