1

A question that was asked among a few developers, now deferred to DBA experts:

Is there a way to select multiple columns within a table instead of SELECT'ing columns piecemeal? For example, let's say example table contains 26 columns respectively titled by letters (e.g. A, B, C, etc.). Suppose I would like to retrieve all rows from columns H, I, J, K, L, M, N, O, P- is there a more efficient way to begin the SELECT statement of the following query?

SELECT H, I, J, K, L, M, N, O, P FROM table;

Perhaps something like so?

SELECT H-P FROM table;

Thank you!

0

3 Answers 3

2

This is a crazy idea and would makes future maintenance really tricky.

It is not possible to guarantee that column order will never change. There are plenty of situations where column order changes could potentially be beneficial. It may happen accidentally (update the wrong database) or it may be done for performance reasons (e.g. moving mostly NULL columns to the end).

Even if it is possible - don't do it.

0
1

Since answers were sparse, I relayed this question on the twittersphere, which flagged the attention of Jeff Smith, Senior SQL Developer Product Manager at Oracle. Although he confirmed that no such feature exists yet, he recommended a similar approach referred to as "SELECT * Territory", demonstrated in the following YouTube Screencast, and detailed thusly:

  1. Construct a query like the one in the screenshot below, as if it began with SELECT *:

SELECT * Territory process (1/4)

  1. Delete the *, then highlight the statement within the query-builder window.

SELECT * Territory process (2/4

  1. Next within the table-view window, select the desired columns (on OS X, CMD + mouse-click) to be displayed piecemeal within the resulting query-result window and drop within the query builder, in lieu of * placement.

SELECT * Territory process (3/4

  1. The "Drag and Drop Effects" will prompt; upon selecting "Select" + "Individual Statements" and "Apply" within the aforementioned window, the customized query-view will output as specified.

SELECT * Territory process (4/4

I have verified the above process within my local environment; one thing to note for OS X/Mac users with Retina displays - there's a bug - verify your environment is running Java 8 u40 JDK - that should remediate any freezing when clicking "Apply" within the "Drag and Drop Effects" window. Please feel free to comment herein-thank you!

1
  • 1
    While this is all true, it doesn't do what you asked. Your question was specifically "can you write a query like 'select c1-c3 from t1'" instead of 'select c1, c2, c3 from t1' If your question was really 'Can you make it quicker to write...', that's not the question that you asked. You might have got the answer you wanted if you'd have asked it. Mar 2, 2016 at 16:32
0

No it's not possible but you can create view and use SQL>select * from view_name and you get your result .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.