There is a query: SELECT (SELECT TOP 1 u.id FROM [dbo].[TABLE] tab (nolock) LEFT JOIN BD.dbo.users u ON u.id=tab.menID WHERE tab.ID = t.mID) c_id FROM dbo.[Tables] t (nolock) WHERE c_id=1

The error is Invalid column name 'c_id'. How can I refer to the c_id column to set a condition? Thank.

  • Wrap in one large external select * from (ваш запрос) where c_id=1 . But it will turn out very badly. because first all records from Tables will be selected, then a subquery will be executed for each of them and finally a condition will be applied which will filter the records. Worth looking for a radically different approach to the problem - Mike
  • one
    And by the way, top 1 without an order by looks very strange, you really need one arbitrary entry, i.e. not the minimum, not the maximum, but the first one that comes in (which one will fall is impossible to predict, depending on how the disk is lying and the moon phase a little more) - Mike
  • Yes, what a strange request. Can describe the task? And there it may already need to be done in a completely different way? - Ella Svetlaya
  • Thank you all for your help, the problem is solved. The decision was in the join. Thank :). - Maxim Fedorov

0