Search code examples
mysqlsqlquery-builderlaravel-query-builder

how to get data from two table which has no relationship


I have the following tables:

  • patient_medicines (id, drugname, strength, state, quantity, active, patient_id)

  • medicine_products (id, prod_name, prod_generic, prod_state, prod_strength, prod_company, batchno, rate, quantity, prod_expired)

  • stocks (id, medicine_product_id, batchno, rate, quantity, discount, date)

since there is no association of relation between patient_medicines and medicine_products table, i want to get all the patient drugname from the patient_medicines and show the availaible quantity by subtracting the stocks.quantity - patient_medicines.quantity as availablenow [in stocks] if the patient_medicines is not in the product_medicines table then show "not_available_in_stock"


Solution

  • Eveyone thank you for your time i solved it by lef joining the patient_medicines and product based on their name and state