Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > SQL Language
|
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 28th, 2005, 06:40 AM
Registered User
 
Join Date: Feb 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default first and last sql?


say i do a select statement and I get 5 record sets returned. each record set has a different number of variables ie.

r1 - xyz123, udf432, asf909, lkj011
r2 - kjf092, sdf092
r3 - dsf025, dsl985, fds986
r4 - sdf021
r5 - dsa349, fds543, xcv941, fiz091, fgs431, oiz012

what i'd like to do, is instead of getting all of the values in each record set, i'd like to only extract the 1st and the last ie.

r1 - xyz123, lkj011
r2 - kjf092, sdf092
r3 - dsf025, fds986
r4 - sdf021
r5 - dsa349, oiz012

Is this possible using 1 sql?

 
Old February 28th, 2005, 02:33 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

By variables I assume you mean columns.
Just use a Select <col1>, <col_last> From <Table>.
 
Old March 1st, 2005, 01:54 AM
Authorized User
 
Join Date: Feb 2005
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Before thinking about the query i would like to know first, whether the data of r1 "xyz123, udf432, asf909, lkj011" belongs to one column OR four columns ?

Cheers,
Pooja Falor
 
Old March 1st, 2005, 02:09 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

You need to be more clear in your explanation:

If you do a Select statment, the number of columns returned is always the same. The number of rows will vary depending on your Where clause.

Are you asking if a value repeats across many columns?:
Ex .. Col1 Col2 Col3 Col4
row1 - Val1 Val2 Val1 Val3

Do want to know that Val1 appears in 2 columns in row 1?


First lets start with your SQL. Please post your SQL statement for me to check.

Jim





Similar Threads
Thread Thread Starter Forum Replies Last Post
How Run .sql Script file in MS SQL Server 2000? aarkaycee SQL Server 2000 5 October 12th, 2009 05:43 AM
creating ssis packagte for sql server to sql serer Laxmikant_it ASP.NET 3.5 Professionals 0 November 26th, 2008 12:23 AM
Converting from MS SQL 2005 to Sql Epress edition saif44 SQL Language 0 February 16th, 2007 04:17 PM
Failed to copy objects from SQL server to SQL Serv monfu SQL Server 2000 4 December 4th, 2005 05:54 PM
Move SQL DB from one sql to another sql server Israr SQL Server 2000 3 January 24th, 2005 02:13 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.