The Forum has been Updated
The code has been upgraded to the latest .NET core version. Please check instructions in the Community Announcements about migrating your account.
I have three issues.
- Select distinct values for one field if ALL values for another field are identical - like this:
SELECT DISTINCT A, B FROM TABLE WHERE (ALL B=1) - Identify whether values are repeated in a column, if certain other conditions are also met - like this:
SELECT DISTINCT A, B FROM TABLE WHERE (C>'' AND B='') GROUP BY B HAVING COUNT(*) > 1 - Identify distinct values when values in another column are repeated - like this:
SELECT DISTINCT A, B FROM TABLE GROUP BY (B HAVING COUNT(*) > 1) ORDER BY A ASC
آخرین ویرایش توسط
نوشته شده در
are those exactly as you have executed them ?
نوشته شده در
Yes
نوشته شده در
when you execute them, do they error or just not return what you were expecting?
نوشته شده در
They just freeze until they timeout. I think using ALL in #1 tells it that I'm retarded but #2 & #3 are due to using "distinct AND group by" in the same query, but I haven't found anything saying that I shouldn't.
نوشته شده در
You wouldn't normally use a DISTINCT clause that way, if you are using groupby since grouping by stuff is very similar to requesting distinct anyway
instead try doing something like
SELECT A, B FROM TABLE WHERE (C>'' AND B='') GROUP BY B HAVING COUNT(DISTINCT A) > 1
instead try doing something like
SELECT A, B FROM TABLE WHERE (C>'' AND B='') GROUP BY B HAVING COUNT(DISTINCT A) > 1
نوشته شده در
No, didn't work. Same result. Thanks for trying.
نوشته شده در
Does your table have a primary key? If it does, 1. and 3. can be solved using IN and a subquery.
نوشته شده در
Yes, it does. Have an example of how to handle 3?
نوشته شده در
The subquery would be something like (SELECT B FROM TABLE GROUP BY B HAVING COUNT(*)>1) and the overall query could be:
SELECT DISTINCT A FROM TABLE WHERE B IN (SELECT B FROM TABLE GROUP BY B HAVING COUNT(*)>1 )
I did this without testing, so it may actually need a bit of testing to make sure it would work as you'd want.
SELECT DISTINCT A FROM TABLE WHERE B IN (SELECT B FROM TABLE GROUP BY B HAVING COUNT(*)>1 )
I did this without testing, so it may actually need a bit of testing to make sure it would work as you'd want.
نوشته شده در
Sorry for my delay in replying, I've been trying to make it work (without success).
Email Member
Message Member
Post Moderation
بارگزاری فایل
If you're having problems uploading, try choosing a smaller image.
پیشنمایش مطلب
Send Topic
Loading...