I have a table A.
|----+----| | P | S | |----+----| | p1 | 1 | | p2 | 7 | | p3 | 14 | | p4 | 23 | | p5 | 1 | |----+----|
and table B
|----+----| | S | C | |----+----| | 1 | 21 | | 5 | 21 | | 23 | 21 | | 1 | 30 | | 7 | 90 | |----+----|
I need to sort table A.
Sorting order:
A. TableA.S exists where (TableA.S = TableB.S) and TableB.C = 21 B. TableA.P
Final Output:
|----+----| | P | S | |----+----| | p1 | 1 | | p4 | 23 | | p5 | 1 | | p2 | 7 | | p3 | 14 | |----+----|
This needs to be converted to DBIx::Class query.
I tried following:
Select tableA.P, tableA.S from tableA left join tableB on tableA.S = tableB.S where (tableB.C = 21 or tableB.C is NULL) order by tableB.C, tableA.P
But I am missing somewhere to get the result where tableB.S is ‘7’.
Thanks.
This sorts by
A.Pfor all the records in A a matching record is found in B then byA.Pfor the other records.