Here is a pseudo code what I want.
I need to get count of fist union in following statement.
SELECT *
FROM Table1
UNION
SELECT Cats.Id + (SELECT COUNT(*) FROM Fist_Union_Result),
Cats.Name
FROM Table2
Any idea ?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Assuming that the first part is a complex query, you could use the
withclause to alias it. That allows you to use it in two places, the top part of the union and the place where you count:If you just want a unique ID, you could place the
unionin a subquery and just label the rows 1..N: