I am trying to write a query returns a column that satisfies a where condition and only the distinct values in another column in SQL. Is this possible?
Below is my current query, I need to add the distinct condition for proposal_order.
SELECT *
FROM [dbo].[proposal_descriptions]
WHERE sku IN ('FAS100', 'SHN100', 'UND100') AND job_type = 1
It returns the following table
sku | job type | proposal_description | proposal_order |
---|---|---|---|
fas100 | 1 | tear off the existing | 10 |
fas100 | 1 | prepare wood sheath | 40 |
UND100 | 1 | sand the material | 45 |
SHN100 | 1 | install shingle brand | 120 |
SHN100 | 1 | install shingle brand | 120 |
SHN100 | 1 | install shingle brand | 120 |
MEM100 | 5 | Adhere membrane to roof | 30 |
MEM100 | 5 | Adhere membrane covering | 35 |
FLS100 | 5 | Remove flashing | 40 |
FLS100 | 5 | Remove flashin | 40 |
Notes:
- Some skus have multiple of the same descriptions associated with them. To remove duplicates, we want to remove the rows where the sort order is the same. This led me to think that the distinct function would be a way to solve this.
I need it to return only the proposal description column in the end. But only the description that satisfy the where clause above and only the rows with distinct proposal_order values. This would result in the following table.
proposal_description |
---|
tear off the existing |
prepare wood sheath |
sand the material |
install shingle brand |
CodePudding user response:
SELECT distinct proposal_description
FROM [dbo].[proposal_descriptions]
WHERE sku IN ('FAS100', 'SHN100', 'UND100') AND job_type = 1