How can I check the validity of a column elements in MySQL that were derived from another column of the same table?

120

Question: How can I check the validity of a column elements in MySQL that were derived from another column of the same table?

For example, if I have a Project_ID = 123456 in one column and Project_Name mysql error = R123456. I want to check if Project_Name was correctly input with prefix R in every elements. What query can I use?

Total Answers: 1

5

Answers 1: of How can I check the validity of a column elements in MySQL that were derived from another column of the same table?

select Project_ID,        case when Project_Name = concat('R', Project_ID)              then 'ok'              else 'fail'        end as result from your_table 

or to get only the ones that are not correct:

select Project_ID from your_table where Project_Name <> concat('R', Project_ID)