sql query construction help


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Thread: sql query construction help

  1. #1
    Join Date
    Jun 2006
    Posts
    168

    sql query construction help

    hi guys.


    I need to construct a query to get the following data.


    select (param1, param2, param3) WHERE Param2 = (Max(param2)-1)


    much simplified, of course. but how can i do this with a SQL query?
    -Jon


    Visual Basic 6.0
    Microsoft Access 2003

  2. #2
    Join Date
    Jun 2006
    Posts
    168
    ok and just realized, not EXACTLY -1. but like -1 .3
    -Jon


    Visual Basic 6.0
    Microsoft Access 2003

  3. #3
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    You don't mention what database you're using, but you might try this:

    SELECT (param1, param2, param3) FROM TableName
    WHERE param2 = (SELECT Max(param2) - 1 FROM TableName)
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  4. #4
    Join Date
    Jun 2006
    Posts
    168
    Quote Originally Posted by Phil Weber
    You don't mention what database you're using, but you might try this:

    SELECT (param1, param2, param3) FROM TableName
    WHERE param2 = (SELECT Max(param2) - 1 FROM TableName)

    Access 03



    is there a way i can do it -1 plus or minus 0.3 ?
    -Jon


    Visual Basic 6.0
    Microsoft Access 2003

  5. #5
    Join Date
    Jun 2006
    Posts
    168
    got it. thanks Phil.


    this is for my application, but maybe someone else would need something similar

    Code:
    SELECT DISTINCT [Table_Name].[Param1], [Table_Name].[Param2], [Table_Name].[Param3], [Table_Name].[Param4], [Table_Name].[Param5], [Table_Name].[Param6], [Table_Name].Param7, [Table_Name].Param8, [Table_Name].Param9, [Table_Name].Param10, [Table_Name].[Param11]
    FROM Table_Name
    WHERE	(
    	((([Table_Name].[Param3])=3.3) AND (([Table_Name].[Param4])=0.2) AND (([Table_Name].[Param5])=100) AND (([Table_Name].[Param6])=4900) AND (([Table_Name].Param7)="CWRF") AND (([Table_Name].Param8)="AN1-RA1") AND (([Table_Name].Param9)="AN1-RA1") AND (([Table_Name].[Param11])=25) AND ([Table_Name].Param10 Like "*5")) AND
    	([Table_Name].[Param2])>(
    	SELECT (MAX([Table_Name].[Param2])-1.01) FROM [Table_Name]
    	WHERE ((([Table_Name].[Param3])=3.3) AND 
    	(([Table_Name].[Param4])=0.2) AND 
    	(([Table_Name].[Param5])=1) AND 
    	(([Table_Name].[Param6])=4) AND 
    	(([Table_Name].Param7)="CW") AND 
    	(([Table_Name].Param8)="this") AND 
    	(([Table_Name].Param9)="this") AND 
    	(([Table_Name].[Param11])=25)
    	AND ([Table_Name].Param10 Like "*5")
    	))
    	AND 
    	(([Table_Name].[Param2])<(SELECT (MAX([Table_Name].[Param2])-0.99) FROM [Table_Name]
    	WHERE (
    	(([Table_Name].[Param3])=3.3) AND 
    	(([Table_Name].[Param4])=0.2) AND 
    	(([Table_Name].[Param5])=1) AND 
    	(([Table_Name].[Param6])=4) AND 
    	(([Table_Name].Param7)="CW") AND 
    	(([Table_Name].Param8)="this") AND 
    	(([Table_Name].Param9)="this") AND 
    	(([Table_Name].[Param11])=25) AND 
    	([Table_Name].Param10 Like "*5")
    	)	))
    	);
    -Jon


    Visual Basic 6.0
    Microsoft Access 2003

Similar Threads

  1. Replies: 0
    Last Post: 11-30-2006, 06:58 AM
  2. SQL2000 remote SQL query
    By lightningtechie in forum Database
    Replies: 1
    Last Post: 02-07-2006, 09:34 AM
  3. Return Query Estimate for SQL Server 2000
    By Daniel Reber in forum VB Classic
    Replies: 0
    Last Post: 09-16-2002, 03:50 PM
  4. SQL Query Fails on NT System
    By Ken D. in forum VB Classic
    Replies: 2
    Last Post: 09-04-2002, 12:25 AM
  5. IIF in SQL Query Analyzer
    By Jeff Johnson in forum Database
    Replies: 3
    Last Post: 04-30-2001, 03:42 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center