简体   繁体   中英

SQL Select All Where the Concat is Distinct

I am looking to create a select statement where I select all columns and rows when the concatenation of two of the rows is distinct. I have my SQL statement below. However, I am not sure how to properly create this statement, how would this statement be written?

$query = "SELECT * FROM APPROVED 
  WHERE DISTINCT CONCAT(P_NUMBER,'-',A_NUMBER) AS CNUMBER 
  AND (STATUS = 'ACTIVE' OR STATUS = 'CLOSED' OR STATUS = 'CLOSING' OR STATUS = 'PENDING')"; 

DISTINCT is used on the column selection. There are a couple ways to do this:

SELECT DISTINCT CONCAT(P_NUMBER,'-',A_NUMBER) AS CNUMBER FROM APPROVED WHERE 
AND (STATUS = 'ACTIVE' OR STATUS = 'CLOSED' OR STATUS = 'CLOSING' OR STATUS =     'PENDING')

that should do almost the same thing as

SELECT * FROM APPROVED WHERE 
AND (STATUS = 'ACTIVE' OR STATUS = 'CLOSED' OR STATUS = 'CLOSING' OR STATUS =     'PENDING')
GROUP BY CONCAT(P_NUMBER,'-',A_NUMBER)

the 2nd doesn't include the concatenation in the results, and the first one ONLY includes the concatenation. You'll need to specify all the columns to return.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM