List:General Discussion« Previous MessageNext Message »
From:John List Date:December 28 2009 1:25am
Subject:Re: Is there a better way than this?
View as plain text  
On 12/27/2009 06:04 PM, Tim Molter wrote:
> I'm new to MySQL and I'm looking for some guidance. I have a table A,
> with two columns X and Y with the following data:
>
> |   X    |    Y    |
>     1          24
>     1          25
>     2          25
>     2          26
>     3          27
>
> I want my SQL query to return "2" following this verbose logic: SELECT
> DISTINCT X FROM A WHERE Y equals 25 and Y also does NOT equal 24.
Since y=25 is associated with both x=1 and x=2, there's no way a simple 
select can result in 2.

Perhaps your assignment calls for the count()  of the results?

select count(*) from A where y = 25

Good luck,

John

Thread
Is there a better way than this?Tim Molter28 Dec
  • Re: Is there a better way than this?John List28 Dec
  • Re: Is there a better way than this?Chris W28 Dec
    • Re: Is there a better way than this?Tim Molter28 Dec
    • RE: Is there a better way than this?Gavin Towey28 Dec
      • Re: Is there a better way than this?Michael Dykman28 Dec
  • Re: Is there a better way than this?DaWiz28 Dec