madan
madan

Reputation: 171

How to display an additional column along with all the columns in oracle db

The scenario is that, I want to write a query to display all the columns of a table along with an additional column.

E.g.:

I want to display all the columns and rows of jobs table, which can be done by select * from jobs;

Now I also want the diff between min_salary and max_ salary to be displayed along with all the others columns. So I did try like, select *, max_salary - min_salary salaryDiff from jobs; this is not a valid query, it shows.

So I tried the traditional way, select job_id, job_title, min_salary, max_salary, max_salary - min_salary salaryDiff from jobs; this works.

This is not a tough job since in the above example it has only 4 columns, but, what if a table has 10 or 20 columns and we ran into a scenario like this? is traditional way the only way? or is there any other way to do it?

Upvotes: 1

Views: 102

Answers (1)

René Nyffenegger
René Nyffenegger

Reputation: 40499

You have to prefix the * with the table name (or its alias) that the star refers:

select jobs.*, max_salary - min_salary salaryDiff from jobs;

Same thing, but with an alias:

select j.*, max_salary - min_salary salaryDiff from jobs j;

Upvotes: 2

Related Questions