Executing SQL query on two tables
I am wondering if it is possible to make a sql query that does the same function as
'select products where barcode in table1 = barcode in table2
. I am writing this function in a python program. Once this function is called, will the table be joined permanently or only during the execution of this function? Thank you.
source to share
Here you can talk about yourself through the table design in these cases based on modeling the role of objects. (Yes, I understand that this is indirectly related to the question.)
You have products and barcodes. Products are uniquely identified by their product code (eg "A2111", barcodes are uniquely identified by value (eg 1002155061).
The product has a barcode. Questions: Can the product not have a barcode? Can the same product have multiple barcodes? Can multiple products have the same barcode? (If you have experience with UPC shortcuts, you know the answer to all of this is TRUE.)
So, you can make some statements:
The product (code) has zero or more barcode (value).
A barcode (value) has one or more products (code). - assumption: we, barcodes, do not have an independent existence if they were not / were / were not associated with products).
Which leads directly (via your ORM) to a two-table schema:
Product Code (PK) Description, etc.
ProductBarcode
ProductCode (FK) BarcodeValue
- with two-part natural primary key, ProductCode + BarcodeValue
and you link them together as described in other answers.
Similar statements can be used to determine which fields go into different tables in your design.
source to share