# KDB Converting Subselect to Q Query

**URL:** <https://forum.kx.com/t/kdb-converting-subselect-to-q-query/11570>\
**Category:** Community Support\
**Tags:** kdb-and-q\
**Created:** [July 3, 2017, 4:42pm UTC](https://forum.kx.com/t/kdb-converting-subselect-to-q-query/11570 "2017-07-03T16:42:00Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Birzos](https://avatars.discourse-cdn.com/v4/letter/b/ec9cab/32.png) [@Birzos](https://forum.kx.com/u/Birzos)\
**Post date:** [July 3, 2017, 4:42pm UTC](https://forum.kx.com/t/kdb-converting-subselect-to-q-query/11570/1 "2017-07-03T16:42:00Z")

</div>

We have a Q query running on tick data which consolidates to OHLC on 1minute bars.

```
select subsel:(exec last datetime.date+1 xbar datetime.minute.z.Z from `base where instrument=`GBPUSD, datetime=datetime.date+1 xbar datetime.minute.z.Z), max(datetime),min(datetime),Open:first price,High:max price,Low:min price,Close:last price,Volume:count(i) by DT:($)datetime.date+1 xbar datetime.minute.z.Z from `base where instrument=`GBPUSD, datetime>=2017.07.03T10:20:00.00,datetime<2017.07.03T10:20:59.999

```

The problem is the xbar date is synthetic on both the main table and the ‘subselect’, the exec “datetime=” needs to reference the main table and cannot find the alias approach to use. Considered an ej but as both sides are synthetic also could not find the construct.
