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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

(my)SQL Filtering

Status
Not open for further replies.

citizendc

Programmer
Joined
Nov 20, 2003
Messages
2
Location
ZA
Hi Guys,

Lets say I have two fields in a Database (DB1):

-------------------
Field1(txt) | Field2(txt)

a | x
b | x
c | y
d | y
e | Z

I need to SELECT * FROM DB1
(where 1x(field2 = field2))

The above into words, would mean, i'd like the fields in field2 to be distinct, so for example my end results would be:

Field1(txt) | Field2(txt)
a | x
c | y
e | z


Here is the problem, i can't use sub queries because of the version of MYSQL,

Any other ideas?



Thanks in advance.


Cheers,

-L.
 
if yo don't mind what's returned in the field1 you can use
SELECT * FROM DB1 GROUP BY Field2

 
How do you decide which value should be choosen from field1? I.e. why a,c and not b,d?

Code:
select min(field1),field2 from t
group by field1


What has this to do with subqueries?
 
Hi Guys,

Thanks for the help. Until earlierly mentioned, GROUP BY was missing from my SQL vocabulary. I was looking for a way to do the same thing as what 'group by' does, which is the summarising of records. The alternative was to use sub queries in a complex query, but thanks 2 u guys, there is no need now.

Cheers,
L
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top