In a Paragraph can we use the results of a SELECT statement in another SELECT criteria?

60 views Asked by At

Within a paragraph, is there a way to take the results of one SELECT statement and use them in another SELECT statement?

For example, if I have the following SELECT statement:

SELECT PROGRAM.REQ WITH CREDITS GT 0 AND CREDITS LT 15
SAVING UNIQUE PROGRAM.REQ.PROG.ID 
SAVE.LIST SHORT.PROGRAMS

Could I then take the savedlist SHORT.PROGRAMS and use it within another SELECT statement like:

SELECT PROGRAMS WITH PROGRAM.ID
<in the savedlist SHORT.PROGRAMS>

I tried searching the "Using UniQuery 8.23" manual for any keywords or examples that might help, but had no luck. Is there a better manual or one that specifically discusses what EVAL can do?

Right now I am manually taking the results and placing them into the select statement. So if SELECT statement 1 returns One Two Three, then I just do:

SELECT PROGRAMS WITH PROGRAM.ID
EQ 'One' 'Two' 'Three' 

Which works for my purposes, just seems very inefficient. Thank you!

2

There are 2 answers

0
Galaxiom On

BTW Select lists can also be used in UniverseSQL.

LT and GT and their variants can be used for the criteria but SQL also supports BETWEEN.

SELECT DISTINCT PROGRAM.REQ.PROG.ID TO SLIST 'SHORT.PROGRAMS' 
FROM PROGRAM.REQ WHERE CREDITS BETWEEN 1 AND 14

Then use GET.LIST as Ian McGowan advised to activate the list in the subsequent sentence of query.

Select lists can be applied in UniverseSQL too. Though this particular query is somewhat redundant in this context they are specified like this.

SELECT PROGRAM.ID FROM PROGRAMS SLIST 'SHORT.PROGRAMS'

With an @SELECT entry in DICT PROGRAM this query can be used.

SELECT * FROM PROGRAMS SLIST 'SHORT.PROGRAMS'
0
Ian McGowan On

Before doing another command that is supposed to use the saved list do:

GET.LIST SHORT.PROGRAMS
<LIST OR SORT that uses that set of keys>

From TCL, HELP SAVE.LIST and HELP GET.LIST for more detailed information, or each command has a section in "Uniquery Commands Reference v 8.2.4".

For more information on EVAL and the various options, look in the "Using Unidata v 8.2.4", Chapter 5, "Creating virtual attributes".