Drop Table

Support Forum for database administrators and web based access to important newsgroups related to databases
Register on Database Support Forum Edit your profileCalendarFind other Database Support forum membersFrequently Asked QuestionsSearch this forum -> 
For Database admins: Free Database-related Magazines Now Free shipping to Texas


Post New Thread










Thread
Author

Selecting Min/Max over multiple rows
Hello All,

I have this table:

CREATE TABLE [dbo].[tbl_TESTING] (
[ROW_ID] [int] IDENTITY (1, 1) NOT NULL ,
[FNAME] [varchar] (50) COLLATE  SQL_Latin1_General_C
P1_CI_AS NULL ,
[LASTNAME] [varchar] (50) COLLATE  SQL_Latin1_General_C
P1_CI_AS NULL 
,
[MOVEDINYR] [int] NULL ,
[MOVEDOUTYR] [int] NULL
) ON [PRIMARY]
GO

with these records:

INSERT INTO tbl_TESTING
VALUES
(
'JAMES', 'TAYLOR', '1995', '2000'
)

INSERT INTO tbl_TESTING
VALUES
(
'JAMES', 'TAYLOR', '1994', '2005'
)

What I would like to do is be able to select FIRSTNAME, LASTNAME,
MIN(MOVEDINYR), MAX(MOVEDOUTYR) for JAMES TAYLOR e.g.

FIRSTNAME=JAMES
LASTNAME=TAYLOR
MOVEDINYR=1994
MOVEDOUTYR=2005



Some sql syntax help appreciated,

thanks in advance!


Report this thread to moderator Post Follow-up to this message
Old Post
hharry
05-24-05 04:23 PM


Re: Selecting Min/Max over multiple rows
On 24 May 2005 08:33:16 -0700, hharry wrote:

>Hello All,
>
>I have this table:
>
>CREATE TABLE [dbo].[tbl_TESTING] (
>	[ROW_ID] [int] IDENTITY (1, 1) NOT NULL ,
>	[FNAME] [varchar] (50) COLLATE  SQL_Latin1_General_C
P1_CI_AS NULL ,
>	[LASTNAME] [varchar] (50) COLLATE  SQL_Latin1_General_C
P1_CI_AS NUL
L ,
>	[MOVEDINYR] [int] NULL ,
>	[MOVEDOUTYR] [int] NULL
> ) ON [PRIMARY]
>GO
>
>with these records:
>
>INSERT INTO tbl_TESTING
>VALUES
>(
>	'JAMES', 'TAYLOR', '1995', '2000'
> )
>
>INSERT INTO tbl_TESTING
>VALUES
>(
>	'JAMES', 'TAYLOR', '1994', '2005'
> )
>
>What I would like to do is be able to select FIRSTNAME, LASTNAME,
>MIN(MOVEDINYR), MAX(MOVEDOUTYR) for JAMES TAYLOR e.g.
>
>FIRSTNAME=JAMES
>LASTNAME=TAYLOR
>MOVEDINYR=1994
>MOVEDOUTYR=2005
>
>
>
>Some sql syntax help appreciated,
>
>thanks in advance!

Hi hharry,

SELECT   MIN(MovedInYr), MAX(MovedOutYr)
FROM     Testing
WHERE    FName = 'James'
AND      LastName = 'Taylor'

Or, if you want it for all people at once:

SELECT   FName, LastName, MIN(MovedInYr), MAX(MovedOutYr)
FROM     Testing
GROUP BY FName, LastName

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)

Report this thread to moderator Post Follow-up to this message
Old Post
Hugo Kornelis
05-25-05 01:23 AM


Re: Selecting Min/Max over multiple rows
all set, thanks hugo!


Report this thread to moderator Post Follow-up to this message
Old Post
hharry
05-25-05 01:24 AM


Sponsored Links





Last Thread Next Thread
Post New Thread

Microsoft SQL Server forum archive

Show a Printable Version Email This Page to Someone! Receive updates to this thread
Microsoft SQL Server
Access database support
PostgreSQL Replication
SQL Server ODBC
FoxPro Support
PostgreSQL pgAdmin
SQL Server Clustering
MySQL ODBC
Web Applications with dBASE
SQL Server CE
MySQL++
Sybase Database Support
MS SQL Full Text Search
PostgreSQL Administration
SQL Anywhere support
DB2 UDB Database
Paradox Database Support
Filemaker Database
Berkley DB
SQL 2000/2000i database
ASE Database
Forum Jump:
All times are GMT. The time now is 11:41 PM.

 
Mobile devices forum | Database support forum archive




Copyrights DropTable.com Database Support Forum 2004 - 2006