It is good to specify the fields in this way (minimally), but for the primary key and signature / name. If you consistently name your entire primary key as ID and name as Name, the construction of the request degenerates into redundant aliases:
select i.id as invoice_id v.id as vendor_id, p.id as product_id, v.name as vendor, p.name as product, b.name as branch, c.name as parcel, i.total_amount, i.discount, i.invoice_date from invoice i join product p on i.product_id = p.id join vendor v on i.vendor_id = v.id join branch b on i.branch_id = b.id join parcel c on i.parcel_id = c.id
As joining tables and displaying the title / name of an entity is the norm, and not an exception, I call my primary key in full form, and for the caption / name field the same name as the table name.
create table product ( product_id uuid not null, -- primary key product text not null, bar_code text not null default '', rfid_code text not null default '', current_qty int default 0 ); create table vendor ( vendor_id uuid not null, -- primary key vendor text not null, is_active boolean not null default true ); create table branch ( branch_id uuid not null, -- primary key branch text not null, sub_branch_of_id uuid, current_sales money not null default 0, ); create table user ( user_id uuid not null, -- primary key user text not null, password text not null default '' );
Thus, your request will not have extra aliases:
select i.invoice_id, p.product_id, v.vendor, p.product, b.branch, c.parcel, i.total_amount, i.discount, i.invoice_date from invoice i join product p on o.product_code = p.product_code join vendor v on o.vendor_code = v.vendor_code join branch b on o.branch_code = b.branch_code join parcel c on o.parcel_code = c.parcel_code