Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8304937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:58:09+00:00 2026-06-08T17:58:09+00:00

I have a query with a where cluse like that: WHERE (scalar-subquery1) > (scalar-subquery2)

  • 0

I have a query with a where cluse like that:

WHERE (scalar-subquery1) > (scalar-subquery2)

And it works fine. There can be any operator here instead of “greater than” (“>”) between queries.

Now I want to give a names for these queries so that I can reference them in select clause, so I tried:

SELECT q1,q2 ... WHERE (scalar-subquery1) as q1 > (scalar-subquery2) as q2

But there is syntax error reported between as q1 and > operator. Any way to work around this problem?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T17:58:10+00:00Added an answer on June 8, 2026 at 5:58 pm

    You can do this as a subquery:

    select q1, q2
    from (select (scalar-subquery1) as q1, (scalar-subquery2) as q2
         ) t
    where q1 < q2 
    

    Or as a cross join:

    select q1.val, q2.val
    from(scalar-subquery1) as q1 cross join
        (scalar-subquery2) q2
    where q1.val < q2.val
    

    The third option is a variant of the first:

    select t.*
    from (select <current select>
                 (scalar-subquery1) as q1, (scalar-subquery2) as q2
          from <current from>
         ) t
    where q1 < q2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Query that works like a charm, but now I need to
I have a db query that'll cause a full table scan using a like
I have 2 tables: users and log. Currently my query looks like that. $stmt
I have a query that looks like this WITH CTE AS ( SELECT ROW_NUMBER()
I have a query that looks like this: SELECT last_name, first_name, middle_initial FROM names
I have query that looks like this declare @tmpTable Table(id int) insert into @tmpTable(id)
I have a query that looks like: select distinctrow company.* from company, contact, address,
I have a query that looks like this: surveyCompleted = from s in surveyCompleted
I have a query with a where clause that looks like: WHERE field IN
We have a large-ish query here that has several params, and for each one,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.