简体   繁体   中英

Progress 4GL queries

I am new to this language and having some problems understand queries.

for example:

There are 2 database tables: Warehouse, product. So each warehouse can have multiple products and products can be stored in different warehouses.

Query:
   for each warehouse,
       each product:
   display warehouse.name, product.prodcode.
end.

the display will like

warehousename   productcode
awarehouse       SKA-301

so for this result, are these columns display total independent result, eg. SKA-301 product may not in awarehouse. Or it will display the product in awarehouse? what if product and warehouse don't have related fields?

Please help me. Thank you.

In the code that you have shown you will get each product for every iteration of warehouse.

To get the products that are specific to a particular warehouse you need to add WHERE criteria to the 2nd clause of the join. Assuming that you have a product.warehouseName field that would suit this purpose....

for each warehouse no-lock,
  each product no-lock where product.warehouseName = warehouse.name:

  display
    warehouse.name
    product.prodcode
  .

end.

(If there is no index on product.warehouseName this will be very inefficient.)

Your query is compact version of this expanded version

for each warehouse:
   for each product:
      display warehouse.name, product.prodcode. 
   end.
end.

They both achieve the same thing. I would suggest since you are starting off to expand the query out and once you understand the relationships then go back to the compact each, each version

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM