Wahsei
Wahsei

Reputation: 307

How to check user's permission based on 2 fields - mysql

Have 2 tables

  1. User table with user chat_id, kunnr (cust_code) & vkorg
  2. Delivery table with PO # and other delivery info, cust_code & sales_org

I want to verify if the user cust_code and sales_org match with shipmentdel's table One user can belong to multiple sales org and a PO can have many delivery orders

Below is my working SQL statement, can this be simplified ?

SELECT * FROM ( SELECT a.* FROM ztelegram.ShipmentDel a
WHERE a.Cust_PO = 'WPO-01502') as t1
LEFT JOIN 
( SELECT b.* FROM ztelegram.noti_setting b WHERE b.chat_id = '12345667' ) as t2
ON t1.sales_org = t2.vkorg AND t1.Sold_to_party_name = t2.kunnr

Upvotes: 1

Views: 43

Answers (1)

Praveen
Praveen

Reputation: 415

Without the need of t1 & t2, isnt the query working? Please check.

  SELECT 
    * 
  FROM 
    ztelegram.ShipmentDel a
    LEFT JOIN ztelegram.noti_setting b ON a.sales_org = b.vkorg AND a.Sold_to_party_name = b.kunnr
  WHERE 
    a.Cust_PO = 'WPO-01502'
    and b.chat_id = '12345667' 

Upvotes: 1

Related Questions