SQLite Forum

Ambiguous 'ambiguous error', is it normal or bug?
Login
This would be correct if the query were thus:

```
sqlite> select * from (select * from t a join t b) order by s;
s           s:1
----------  ----------
1           1
1           2
1           3
2           1
2           2
2           3
3           1
3           2
3           3
```

However for a query which is thus:

```
sqlite> select * from t a join t b order by s;
s           s
----------  ----------
1           1
1           2
1           3
2           1
2           2
2           3
3           1
3           2
3           3
```
it should return an error because "s" is ambiguous.  Unless of course the name of the duplicate column "s" were "s:1" and not "s".  The only case in which "s" would not be ambiguous would be if the operation where constrained WHERE a.s IS b.s

Which "s" on which table the query planner might choose to put in an outer loop relating to the other "s" in "undefined" and as such the reference should be ambiguous.

Now if you say'd "order by 1" then it would be clear whichever value was first was what you intended, however, specifying "s" means that you could order by a.s or b.s which is clearly ambiguous.