last day (15 days later) » 

9:18 AM
0
A: Getting error in Oracle "ORA-01400: cannot insert NULL into..." when there are no NULL values

Zaynul Abadin Tuhinit seems you missed AUTHOR_ID in data inserttion INSERT INTO author (AUTHOR_ID,totalrevenue) SELECT AUTHOR_ID,NVL (margin, 0) FROM (SELECT a.AUTHOR_ID , SUM (b.totalmargin) as margin FROM author a LEFT JOIN bookauthor ba ON a.author_id = ba.ba_authorid LEFT JOIN book b ON ba.ba_isbn = b.book_i...

 
In such case you don't need to group by a.author_fname, a.author_lname becasue you're using AUTHOR_ID which seems to be a primary key. Query is really strange because it's trying to insert total revenue for authors instead of an updated
 
@SergeyM this is not mysql it is oracle
 
what's difference if we are speaking about SQL in general. You don't need a.author_Fname, a.author_lname at all. It is not used anywhere and AUTHOR_ID will perfrom grouping on much granular level then other useless columns
 
@SergeyM do some R&D bro you will find the rest
 
I think you didn't get my point. I mean you don't need a.author_fname, a.author_lname columns in group by as well as in select. If you're taking a grouping logic by a.AUTHOR_ID then only a.AUTHOR_ID should be in select list with an aggregates. a.author_fname, a.author_lname become useless in this query. I'm not a mysql expert that's why I know nothing about it's group by extensions. I'm speaking about sql standard
 
9:18 AM
@SergeyM ah got it now yah that is absolutely correct and i edited thanks
 
But thank you Zaynul. Now I know something more about Group by and MySql stuff. Cheers.
 
you are welcome
 
Thanks. I've added one comment more
 
yap i got it but as op does not mentioned anything in his question
 
I think there will be an exception because of primary key violation. If author_id is primary key then your insert should fail on duplicates
 
9:20 AM
author_id primary or not
 
Yep, you're right
 
because it could be not all null
allow*
so i have given answer in this way otherwise it would be updpate
in case of primary key insert is not possible
 
got it. Thank you once again for point on difference between oracle and mysql
have a nice day
 
btw you can upvoted if you think it is useful answer
 
ok
 

last day (15 days later) »