Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select all fields from table A but single field from B?

Tags:

abap

opensql

Is there a way in ABAP's OpenSQL to simplify the select columns in a JOIN when I want to grab all the fields of one table but only selected fields from the other table(s)?

For instance, in mysql we can simply do:

SELECT  tb1.*, tb2.b, tb2.d
FROM       tableA tb1
INNER JOIN tableB tb2 ON tb1.x = tb2.a

However, OpenSQL does not seem to allow selecting tb1~*, tb2~b, tb2~d so I have to resort to this:

SELECT  tb1.x, tb1.y, tb1.z, tb2.b, tb2.d
FROM       tableA tb1
INNER JOIN tableB tb2 ON tb1.x = tb2.a

For very large tables, especially standard tables, this becomes unwieldy, difficult to read and more annoying to maintain.

Is there a better way to select all fields of tb1 and some fields from tb2?

like image 400
Lilienthal Avatar asked Jun 23 '16 11:06

Lilienthal


People also ask

How do I SELECT all columns from one table and one column from another in SQL?

How do I SELECT all columns from one table and one column from another in SQL? SELECT column1, column2, FROM table_name; SELECT * FROM table_name; Example.

How do I exclude a column from a selected query?

A MySQL SELECT statement is used to retrieve data from a MySQL table. To exclude certain column(s) from the SELECT statement result, you can omit the column/ field name from the query.

How do you SELECT all records in one table that does not exist in another table?

How to Select All Records from One Table That Do Not Exist in Another Table in SQL? We can get the records in one table that doesn't exist in another table by using NOT IN or NOT EXISTS with the subqueries including the other table in the subqueries.


1 Answers

Yes, this is possible in the OpenSQL from 7.40 SP08. See this article.

The quotation from the article has that.

Column Specification

In the SELECT list, you can specify all columns of a data source using the syntax data_source~* from 7.40, SP08 on. This can be handy when working with joins.

SELECT scarr~carrname, spfli~*, scarr~url
       FROM scarr INNER JOIN spfli ON scarr~carrid = spfli~carrid
       INTO TABLE @DATA(result).

In the previous versions unfortunately one has to specify the columns one by one or use database native SQL for example with ADBC.

like image 176
Jagger Avatar answered Oct 07 '22 01:10

Jagger