Search code examples
mysqlsqldatabasesap-erp

Query fields from different mysql tables


I have this RELATIONSHIP in my database...

enter image description here

I need to get from TABLE: MSEG the MATNR field and from the MAKT table the MAKTX field entering only the MBLNR field from my MSEG table, IS THIS POSSIBLE????

In other words, I try to search for MBLNR='426665' and I get the fields from the MSEG and MAKT table.


Solution

  • you need to join the tables as follows

    SELECT MSEG.MATNR, MAT.MAKTX
    FROM MSEG JOIN MAKT ON MSEG.MATNR=MAKT.MATNR
    WHERE MSEG.MBLNR = '1337'
    

    Replace 1337 with the MBLNR you look for. I assumed it is a String, if its not just remove the ' before and after the number.