Never Stop Learning
Never Stop Learning

Reputation: 785

Select columns in 3 tables if it is null or not

I am learning more in PL/SQL Toad for Oracle. I want to select some columns in 3 tables and then I use case statements to execute if it is Null or Not. This is my sample script.

SELECT (CASE WHEN a.column1 is NULL
             THEN 'Active'
             ELSE 'Inactive'
             END) as Status_Define_Resources, <<some columns>>,

       (CASE WHEN b.column1 is NULL
             THEN 'ACTIVE'
             ELSE 'INACTIVE'
             END) as STATUS_USER, <<some columns>>,

                   c.LASTNAME, c.FIRSTNAME, c.MIDDLENAME

FROM table1 a, table2 b, table3 c

It is running.. my problem is I want to combine column names c.LASTNAME, c.FIRSTNAME and c.MIDDLENAME any ideas? And sorry I am new in Toad for Oracle PL/SQL.

Upvotes: 1

Views: 388

Answers (1)

Charlesliam
Charlesliam

Reputation: 1313

You can use Concatenation. Here's a example.

But in your case

SELECT (CASE WHEN a.column1 is NULL
         THEN 'Active'
         ELSE 'Inactive'
         END) as Status_Define_Resources, <<some columns>>,

   (CASE WHEN b.column1 is NULL
         THEN 'ACTIVE'
         ELSE 'INACTIVE'
         END) as STATUS_USER, <<some columns>>,

    c.LASTNAME||','||c.FIRSTNAME||','||c.MIDDLENAME as "Complete Name"

FROM table1 a, table2 b, table3 c

I assume the 3 tables are related by a Foreign Key then used Join Statements

Upvotes: 1

Related Questions