Jump to content

Recommended Posts

Hello,

 

I have a query "INSERT INTO SELECT".

It's quite huge, so i minimize it with a simple example

 

INSERT INTO table (NAME, PRICE, CATEGORY, ORDER)

SELECT a.name, a.price, a.category, a.order

FROM table1 AS a

INNER JOIN table2 AS b

ON a.order = b.order

WHERE a.ordered <> (SELECT SUM(QTY) FROM ordered WHERE barcode = a.barcode GROUP BY barcode  )

 

@ table 1 i have 1 record showing the total ordered quantity (324 - barcode 555666), which i want to compare to the SUM of all the QTY from table2, which has 4 records (4* QTY 81 - barcode 555666).

If you get your calculator, you will see it makes 324, so the total quantity is correct.

 

But the query places 3 records into the new table and leaves 1 behind.

It must place all 4 the records into the new table instead of 3.

 

Please help ?

The thing is... I get 3 records placed into `table`

Link to comment
https://forums.phpfreaks.com/topic/238570-insert-into-select/
Share on other sites

Couldn't change the sotry anymore...

 

Hello,

 

I have a query "INSERT INTO SELECT".

It's quite huge, so i minimize it with a simple example

 

INSERT INTO table (NAME, PRICE, CATEGORY, ORDER)

SELECT a.name, a.price, a.category, a.order

FROM table1 AS a

INNER JOIN table2 AS b

ON a.order = b.order

WHERE a.received<> (SELECT SUM(QTY) FROM shipped WHERE barcode = a.barcode GROUP BY barcode  )

 

@ table 1 i have 1 record showing the total ordered quantity (324 - barcode 555666), and the received QTY 0, which i want to compare to the SUM of all the QTY from table2, which has 4 records (4* QTY 81 - barcode 555666).

If you get your calculator, you will see it makes 324, so the total quantity is correct. But since we didn't receive anything, the received QTY is different than the shipped QTY. Now i want all those 4 records moved into the other table.

 

But the query places 3 records into the new table and leaves 1 behind.

It must place all 4 the records into the new table instead of 3.

 

Please help ?

Link to comment
https://forums.phpfreaks.com/topic/238570-insert-into-select/#findComment-1226032
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.