Get a specific entry by group in SQL
Posted
by Jensen
on Stack Overflow
See other posts from Stack Overflow
or by Jensen
Published on 2010-05-26T01:53:49Z
Indexed on
2010/05/26
2:01 UTC
Read the original article
Hit count: 293
Hi,
I've a database who contain some datas in that form:
icon(name, size, tag) (myicon.png, 16, 'twitter') (myicon.png, 32, 'twitter') (myicon.png, 128, 'twitter') (myicon.png, 256, 'twitter') (anothericon.png, 32, 'facebook') (anothericon.png, 128, 'facebook') (anothericon.png, 256, 'facebook')
So as you see it, the name field is not uniq I can have multiple icons with the same name and they are separated with the size field. Now in PHP I have a query that get ONE icon set, for example :
mysql_query("SELECT * FROM icon WHERE tag='".$tag."' ORDER BY size LIMIT 0, 10"); With this example if $tag contain 'twitter' it will show ONLY the first SQL data entry with the tag 'twitter', so it will be : (myicon.png, 16, 'twitter')
This is what I want, but I would prefer the '128' size by default. Is this possible to tell SQL to send me only the 128 size when existing and if not another size ?
Thanks !
© Stack Overflow or respective owner