Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Count (distinct) alternative

Status
Not open for further replies.

skrao12

Technical User
Jul 18, 2005
1
CA
Hi all,

I have recently ported my dbase from MySQL to sqlite and i am having problems porting my sql statements over to sqlite. I cannot use the count (distinct ) feature, and need to workaround this.... what i need is an alternative to this query without the use of count(distinct) .... i need to obtain all the unique x elements that have correlating y elements that exist in table 1 and occur more than once.

table 1 has y
table 2 has x,y

i want to know retrieve all the x's where in table 1 the y values for the same x exceed one element (not the value but the number of y elements in table 1 that have the same x exceeding 1)....i hope this makes my question cleare..thanks again

| SELECT
| | x
| FROM
| | (
| | SELECT DISTINCT
| | | (2.x),
| | | count(DISTINCT(1.y)) AS count
| | FROM 1,
| | | 2
| | WHERE 1.y= 2.y
| | GROUP BY 2.x
| | ) AS collectionOFx
| WHERE count > 1
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top