0

Basically at current i have some script that allows my users to see all distinct values of 'make' which shows the distinct values of a b c ect. But under each of make there is another column which is models. i would like to be abel to select all distinct values of the models column where the make column is equal to a certain make.

Is this possible? if so if someone could point me in the right direction it would be helpful.

current code as follows:

$sql = "SELECT * FROM table_name WHERE make=146";

i would like it to

//SELECT ALL DISTINCT VALUES FROM Column_Name2 where Column_Name1=146.

Surely this is possible and i just can't figure out which function i need to solve my solution.

Many Thanks in Advance.

Lee Sugden
  • 63
  • 8
  • Possible duplicate of [How can I SELECT rows with MAX(Column value), DISTINCT by another column in SQL?](http://stackoverflow.com/questions/612231/how-can-i-select-rows-with-maxcolumn-value-distinct-by-another-column-in-sql) – Laur Ivan Mar 24 '16 at 22:56

3 Answers3

1

You can do it with simple distinct query, e.g.:

select distinct model
from table
where make = '<make>'
Darshan Mehta
  • 30,102
  • 11
  • 68
  • 102
1

Try:

SELECT distinct(Column_Name2) FROM table_name WHERE make=146

David Fernandez
  • 585
  • 1
  • 6
  • 20
1
SELECT DISTINCT
model
FROM table_name
WHERE make = 146;

Regards

White Feather
  • 2,733
  • 1
  • 15
  • 21