Question: I have table1 as below.

| num | value |
| --- | --- |
| 1 | 10 |
| 2 | 15 |
| 3 | 20 |

table2

| ver | value |
| --- | --- |
| 1.0 | 5 |
| 2.0 | 15 |
| 3.0 | 18 |

Output should be as below. I need to select all rows from table1 such that table1.value <= table2.value.

| num | value |
| --- | --- |
| 1 | 10 |
| 2 | 15 |

I tried this, it's not working.

```
select from table1 where value <= (exec value from table2)

```

Answer: 
From a logical point of view what you're asking kdb to compare is:

```
10 15 20<=5 15 18

```

Because these are equal lengths, kdb assumes you mean pairwise comparison, aka

```
10<=5
15<=15
20<=18

```

to which it would return

```
q)10 15 20<=5 15 18
010b

```

What you actually seem to mean (based on your expected output) is `10 15 20<=max(5 15 18)`. So in that case you would want:

```
q)t1:([]num:1 2 3;val:10 15 20)
q)t2:([]ver:1 2 3.;val:5 15 18)
q)select from t1 where val<=exec max val from t2
num val
-------
1   10
2   15

```

As an aside, you can't/shouldn't have a column called `value` as it clashes with a keyword
`value` is a keyword so don't assign to it.

Assuming you want all values from `table1` with value less than the `max` value in `table2` you could do:

```
q)table1:([]num:til 3;val:10 15 20)
q)table2:([]ver:`float$til 3;val:5 15 18)

q)select from table1 where val<=max table2`val
num val
-------
0   10
1   15

```