Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Select into select 1

Status
Not open for further replies.

makisbest

Technical User
Mar 3, 2005
125
GR
How I can put a Select inside another Select ?

For example

Select tape,name,(select type,high from table2) from material

Is that possible?

Please Help.
 
No, You will need to join the tables (or possibly use a function). Have a look at the SQL documentation on joins. Altenatively post the complete table structure(s), and what you wish to achieve and someone can help you construct the syntax.
 
You can add a select into select, but that select must return ONLY ONE field and ONLY ONE record. As Jamfool (WOW what a nick :)) said it is easier to join tables.
I.e. that select is possible:
Code:
SELECT tape,name,
      (select TOP 1 Type from table2 ORDER BY Type) AS Type,
      (select TOP 1 High from table2 ORDER BY High) AS High
from material
but that way you get results that are messy.

Borislav Borissov
 
I agree with bborissov.

I have imbedded an sql select within anothe select statement to return the literal for a code.

For example:

Select MainTable.field1, MainTable.field2, (select literal from LitTable where LitTable.code = MainTable.code), MainTable.field3 from MainTable

[spidey] [americanflag] [unclesam]

I haven't failed. HOWEVER I did find 10,000 ways that do not work.

If life gives you lemons, make lemonade. Then find someone whose life has given them VODKA and have a party.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top