Skip to Content
0
Dec 05, 2022 at 03:43 PM

Select single with max , get record from 2 tables

105 Views

Hello professionals,

i have two tables like this:

tables.png

I want to write Sql query to get the record with the MAX begda.

(25/10/2022)

single record only from all tables.

I tried to do something like this

  SELECT
MAX( BEGDA )
massn
pernr
FROM (
SELECT pernr begda massn
FROM pa0000
UNION ALL
SELECT pernr begda massn FROM pa0302) AS a
INTO CORRESPONDING FIELDS OF TABLE gt_pa0000
UP TO 1 ROWS.

and i tried with CASE:

  SELECT a~pernr
a~massn
a~begda
FROM pa0000 as a LEFT JOIN pa0302 AS b ON a~pernr = b~pernr
CASE a~begda > b~begda THEN a~begda
ELSE a~begda < b~begda THEN b~begda END.


:it's not work.

please help me :)

thanks.

Attachments

tables.png (11.5 kB)