# pass a &quot;select&quot; statement to a user defined function

**URL:** <https://forum.kx.com/t/pass-a-quot-select-quot-statement-to-a-user-defined-function/11548>\
**Category:** Community Support\
**Tags:** kdb-and-q\
**Created:** [June 6, 2017, 3:36pm UTC](https://forum.kx.com/t/pass-a-quot-select-quot-statement-to-a-user-defined-function/11548 "2017-06-06T15:36:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kc3031](https://avatars.discourse-cdn.com/v4/letter/k/aca169/32.png) [@kc3031](https://forum.kx.com/u/kc3031)\
**Post date:** [June 6, 2017, 3:36pm UTC](https://forum.kx.com/t/pass-a-quot-select-quot-statement-to-a-user-defined-function/11548/1 "2017-06-06T15:36:00Z")

</div>

Hi,

I’m new to q/kdb. I’m going to pass a “select” statement to a user defined function and would like it to run row-based.

For example, I have a table:

t:(a:(1 2; 3 4);b:(5 6; 7 8))

and a function:

lm:{[w;y]

x:(w; 1 1f);

x:flip x;

beta:inv[(flip x) mmu x] mmu (flip x) mmu y

}

It seems doesn’t work to use:

lm[select a from t;select b from t]

x:(w; 1 1f); get the result of:

(+`a!(1 2;3 4));1 1)

Can anybody helps? Many thanks!

Best,

Kelly

---

<div class="post-metadata">

**Author:** ![Flying1](https://avatars.discourse-cdn.com/v4/letter/f/f4b2a3/32.png) [@Flying1](https://forum.kx.com/u/Flying1)\
**Post date:** [June 7, 2017, 3:44am UTC](https://forum.kx.com/t/pass-a-quot-select-quot-statement-to-a-user-defined-function/11548/2 "2017-06-07T03:44:00Z")

</div>

lm’[t1;t2]

This passes each row (as a dict) of t1 and t2 into lm.

---

<div class="post-metadata">

**Author:** ![kc3031](https://avatars.discourse-cdn.com/v4/letter/k/aca169/32.png) [@kc3031](https://forum.kx.com/u/kc3031)\
**Post date:** [June 13, 2017, 7:00pm UTC](https://forum.kx.com/t/pass-a-quot-select-quot-statement-to-a-user-defined-function/11548/3 "2017-06-13T19:00:00Z")

</div>

That really helps!  
Thank you!
