MySQL get rows but prefer one column value over another

前端 未结 4 681
忘掉有多难
忘掉有多难 2021-01-24 12:33

A bit of a strange one, I want to write a MySQL query that will get results from a table, but prefer one value of a column over another, ie

id   name    value            


        
4条回答
  •  故里飘歌
    2021-01-24 13:03

    You need to redesign your table first.

    It should be:

    YourTable (Id, Name, Value)
    YourTablePriority (PriorityId, Priority, Id)
    

    Update:

    select * from YourTable a 
    where a.Id not in 
       (select b.Id from YourTablePriority b)
    

    This should work in sql server, you may need a little change to make it work in mysql.

提交回复
热议问题