aquatsr Posted September 18, 2006 Share Posted September 18, 2006 OK so in my databast driven site I like to give the user a variety of choices in sorting by starting letter and catogory. The problem is that when I say, like "Sort by album starting with letter P I get:Phobia - Breaking BenjaminPhobia - Breaking BenjaminPhobia - Breaking BenjaminPhobia - Breaking BenjaminPhobia - Breaking BenjaminPhobia - Breaking BenjaminPhobia - Breaking BenjaminPhobia - Breaking BenjaminPhobia - Breaking BenjaminPhobia - Breaking BenjaminPhobia - Breaking BenjaminBasically it shows every entry that has that... which is good if I was showing the individual song titles - but I'm not. How can I show that my database has Phobia, but not have it show every entry? Link to comment Share on other sites More sharing options...
justsomeguy Posted September 18, 2006 Share Posted September 18, 2006 Use the UNIQUE keyword:SELECT UNIQUE album FROM songs ... Link to comment Share on other sites More sharing options...
aquatsr Posted September 18, 2006 Author Share Posted September 18, 2006 Use the UNIQUE keyword:SELECT UNIQUE album FROM songs ...Thanks! Link to comment Share on other sites More sharing options...
aquatsr Posted September 18, 2006 Author Share Posted September 18, 2006 How would I rework this query? SELECT UNIQUE genre FROM songs WHERE genre LIKE 'r%' ORDER BY genre ASC because it doesn't work.(I'm not good at SQL) Link to comment Share on other sites More sharing options...
justsomeguy Posted September 19, 2006 Share Posted September 19, 2006 Does it give an error, or just not return any data? The LIKE clause is case-sensitive, so make sure that's not the issue. Link to comment Share on other sites More sharing options...
aquatsr Posted September 19, 2006 Author Share Posted September 19, 2006 It gives an error:Could not query the database:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'UNIQUE genre FROM songs WHERE genre LIKE 'I%' ORDER BY genre ASC' at line 1(It's the same whether it's I or r or any letter, regardless of case.) Link to comment Share on other sites More sharing options...
MoZo1 Posted September 19, 2006 Share Posted September 19, 2006 Try DISTINCT instead of UNIQUE! Some sql servers don't like UNIQUE while Oracle uses each. Link to comment Share on other sites More sharing options...
justsomeguy Posted September 19, 2006 Share Posted September 19, 2006 Ooh, good call. I was thinking distinct and came up with unique. MySQL definately uses distinct. Link to comment Share on other sites More sharing options...
aquatsr Posted September 21, 2006 Author Share Posted September 21, 2006 Ooh, good call. I was thinking distinct and came up with unique. MySQL definately uses distinct.Thanks! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now