Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 two selects into one

Author  Topic 

rico16135
Starting Member

11 Posts

Posted - 2008-04-19 : 11:32:02
I've got two queries that I'm using, but I would like to know if I could combine them into one query.

SELECT MAX(ENTRY_ID) FROM MYDB.CALLS
.......
SELECT * FROM MYDB.CALLS WHERE ENTRY_ID = ?(result from previous query)

as always I appreciate any help.
thx

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2008-04-19 : 14:40:27
SELECT * FROM MYDB.CALLS WHERE ENTRY_ID in (SELECT MAX(ENTRY_ID) FROM MYDB.CALLS)
Go to Top of Page

rico16135
Starting Member

11 Posts

Posted - 2008-04-19 : 16:25:37
When I try your query it returns:

Error code -1, SQL state 42X01: Syntax error: Encountered "SELECT" at line 2, column 1.
Go to Top of Page

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2008-04-19 : 16:27:07
Is MYDB schema or databasename?
Go to Top of Page

rico16135
Starting Member

11 Posts

Posted - 2008-04-19 : 16:28:29
it is my database name, i regulary type in MYDB.Calls for my queries
Go to Top of Page

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2008-04-19 : 16:31:16
It goes with 3-part-name like [databasename].[schema].[tablename].
your's should be MyDB.dbo.CALLS
Go to Top of Page

rico16135
Starting Member

11 Posts

Posted - 2008-04-19 : 16:38:36
nm, your previous query does work. I made a mistake, ty for your help
Go to Top of Page
   

- Advertisement -