Jump to content

Alias inside of subquery?


corbin

Recommended Posts

Hello....

 

I'm trying to do:

 

SELECT col1, (CASE WHEN col2 = 1 THEN col5 WHEN col2 = 2 THEN col6) var1 FROM table1 t WHERE col3 IN (SELECT DISTINCT col1 FROM table2 WHERE col2 = var1)

 

(Obviously replaced with bogus names ;p)

 

Anyway, I need to know if that's possible, and if it is, what the syntax is as that gives an error.

 

Thanks,

 

-Corbin

Link to comment
Share on other sites

Blerh can't edit....

 

 

Anyway, I realized I could do:

 

SELECT col1, (CASE WHEN col2 = 1 THEN col5 WHEN col2 = 2 THEN col6) var1 FROM table1 t WHERE col3 IN (SELECT DISTINCT col1 FROM table2 WHERE col2 = (CASE WHEN t1.col2 = 1 THEN t1.col5 WHEN t1.col2 = 2 THEN t1.col6))

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.