Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replace value in result by a specific value

Tags:

sql

I need to make a query to collect some data from a database via SQL. In this data there is 1 value used as collection value. This are ID's of courses given. Sometimes a course can be given about f.e. Office. But people can do a course there for word, excel, powerpoint... But this is all given in 1 course by 1 tutor. Still for statistics I need to know if they participated the course for Word, Excel, Powerpoint ...

Is it possible to replace values in the resultset? With this i mean something like this:

if value = courseValue ==> replace value with specific courseValue (I can get the value via a subquery)

I hope this makes my problem clear and i appriciate all the help!

like image 596
procx Avatar asked Oct 28 '25 02:10

procx


1 Answers

You can use a case statement in your select to return something other than the course id that is on the row. For example:

SELECT 
    field1 AS 'Name',
    CASE 
        WHEN field2 = 'Foo' 
            THEN 'Bar' 
        WHEN field2 = 'Lorem'
            THEN 'Ipsum'
        ELSE 'Some Value'
    END
    AS 'Type',
    field3 AS 'Description'
FROM table
like image 133
DeanOC Avatar answered Oct 29 '25 18:10

DeanOC