0

need help with MySQL query to join one table has closing & opening stock and another table has received the stock. what I want is to join column recvd_value from table recived which stock purchase values to table sales which has an opening and closing stock values here is the DBfiddle what I want is this check this image ---> Output I want

Table1 Screenshot

table2 screenshot

this is my query

SELECT 
    *
FROM
    bar_recvd_details
        INNER JOIN
    bar_opening_details ON bar_recvd_details.item_id = bar_opening_details.item_id
WHERE
    bar_recvd_details.recvd_date = '2018-06-18'
        AND bar_opening_details.close_date = '2018-06-18';
gopal
  • 99
  • 1
  • 9

1 Answers1

0

You can use INNER JOIN sql command for that.

SELECT sales.item_cid, sales.item_id, sales.op_value, sales.close_val, sales.close_date, recived.recvd_value 
FROM sales 
INNER JOIN recived ON recived.item_id = sales.item_id;

This query basically fetchs recvd_value from your recived table where 2 tables item_id's match.

Here's your fiddle:

DBFiddle.Uk

Screenshot from your Fiddle:

enter image description here

Eren Temelli
  • 333
  • 1
  • 14
  • thank u for an answer but here I also want **close_date** column from sales and **recvd_date** from table recived to match because the received stock can be any date but I must able to add that to sales table on that date – gopal Feb 15 '22 at 10:29
  • https://dba.stackexchange.com/q/307556/248088 can u please look at this question for more clarity u can answer there only – gopal Feb 16 '22 at 10:10