Select non matching rows

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
echofool
Forum Newbie
Posts: 16
Joined: Mon Mar 22, 2010 1:15 pm

Select non matching rows

Post by echofool »

Hey,


How do you do a query that selects non matching rows from a single table by camparing values in one field.

Say two rows had:
FieldName : 5
FieldName : 4

This in a query should be noticed and selected as the two rows have different field values.

Any idea how this is done?
User avatar
DigitalMind
Forum Contributor
Posts: 152
Joined: Mon Sep 27, 2010 2:27 am
Location: Ukraine, Kharkov

Re: Select non matching rows

Post by DigitalMind »

If I got you right:

Code: Select all

select distinct fieldname from yourtable
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Select non matching rows

Post by John Cartwright »

otherwise... GROUP BY fieldname
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Select non matching rows

Post by VladSun »

I vote for using DISTINCT.
Using GROUP BY clause just to achieve the DISTINCT functionality should be considered a bad practice.
There are 10 types of people in this world, those who understand binary and those who don't
Post Reply