Re: SQL Newbie Database search question

From: Date: Wed, 31 Jan 2001 18:32:49 +0000
Subject: Re: SQL Newbie Database search question
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-6288@lists.php.net to get a copy of this message
for the second one you can do a subquery: select specific_p from <your table> where specific_p like '%68030% and specific_p in (select distinct specific_p from <your table>); this finds all the distinct specific_p fields and then does a query on them -- that table (remember SQL ONLY returns tables) -- for the like '%68030%'. this may not be exactly what you want, but you can play with it a bit. if you think tables, SQL really makes sense. -lucas On Wed, 31 Jan 2001, Miles Thompson wrote: > add DISTINCT to your query .... > select distinct specific_p, qty from database where specific_p = 68030 and > qty > 0 > > For you second requirement, get them all, and just use the first one ... > can't remember exact syntax but something like > > select specific_p from database where specific_p like %68030% limit 1 > or maybe it's TOP 1. Can't remember. Check your Sql Server docs. > > Miles > > At 08:28 AM 1/31/01 -0600, Robert wrote: > >I have a database with several fields... > >I only want certain fields to show in my results > >Some of the searched fields have the same value > > > >example: searched field is specific_p > >specific_p comment qty > >68030 9845 0 > >68030 9844 100 > >68030 9843 12 > >68030rc50 9843 50 > > > >I want to show the 68030, but not the comment. I also don't want to show > >three seperate 68030s and pick one that is not 0 qty if there is one. > >Is there an MSSQL command to only get one of them? > >There may be other parts that are close too I want to search for %68030% > >to get all of them but show only one of them. > > > >I could probably write a filter, but WHY if it is built into SQL? > > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-db-unsubscribe@lists.php.net > For additional commands, e-mail: php-db-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net > >

« previous php.db (#6288) next »