I have two columns in a database that contain basically the same data but are intended to contain different values. I want to be able to associate articles in this database with others using two fields, category1 and category2. In the HTML form interface my users submit articles in, they're presented with a select menu whose options are built from a "SELECT DISTINCT category1" statement, a text box to enter a new value if the category they want does not already exist in the database. What I want is for the category1 and category2 select menus, but if I "SELECT DISTINCT" on only one or the other of the category fields, there may be other values in the other field that will not be retrieved. Is there away to "SELECT DISTINCT" on both fields and once and build one list of all the distinct values?
Thanks.
select distinct on (field1, field2) field1, field2 from table;
hope it helps
Tried this but MySQL didn't like it. I did a search for that syntax and found numerous references to it in postgresql forums. I suppose I should have specified that I'm using MySQL.
Is there a way I can build a list from my two fields, and then "select distinct" from that compiled list in the same query?
searching for help i found this message, but there is no 'end'..
i have this problem too,.. mysql,
select distinct field1, field2 from table order by field3 limit 4;
i want only field1 to be distinct.
thanks in advance
If you want only feild one to be distinct thats easy
Select Distinct Feild1, otherfeild, otherfeilds, From Tblname Where clause if appliable Order by Feild1;