Can anyone explain this question? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 5

Can anyone explain this question?

https://www.sololearn.com/post/163015/?ref=app

21st Oct 2019, 8:11 PM
Preity
Preity - avatar
30 Answers
+ 12
Preity 1 - If you use this query then results will come wrong and it will display Students name with total marks which is greater than 84. Select S.Student_name, sum(P.Marks) from Student S, Performance P Where P.marks>84 Group BY S.Student_name; 2- if you use this query then Actual results will come Select S.Student_name, sum(P.Marks) from Student S, Performance P Where P.marks>84 and S.Roll_no = p.Roll_no Group BY S.Student_name; 3 - if you remove GROUP BY then this error will come. Column 'Student.Student_name' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
22nd Oct 2019, 8:32 AM
A͢J
A͢J - avatar
+ 10
Ipang I think you didn't understand my previous reply.😂😂 Let me change it. "Primary key of one table can contains duplicate records in other tables but not in Self Table but for other table Primary Key can be foreign key." So Roll_No is Foreign Key in Performance table.
22nd Oct 2019, 9:03 AM
A͢J
A͢J - avatar
+ 7
Ipang Primary key can contains duplicate records in other tables but not in Primary Table but for other table primary key can be foreign key. In Performance table roll_no is Foreign Key
22nd Oct 2019, 8:41 AM
A͢J
A͢J - avatar
+ 5
Ipang Performance.Roll_no is not Primary Key in Performance table that's Foreign Key which refers Table Students. So in table Performance Roll_No can have multiple records.
22nd Oct 2019, 8:54 AM
A͢J
A͢J - avatar
+ 5
Ipang Check again. I posted.
22nd Oct 2019, 9:05 AM
A͢J
A͢J - avatar
+ 4
Is it possible and is it a good idea to use digest as primary key in the database?
23rd Oct 2019, 6:06 AM
Adi Pratama
Adi Pratama - avatar
+ 4
Ipang Check this what I said "Ipang I was not saying that Roll_No in Performance Table is Primary Key. Let me explain this line :- "But for other table Primary key can be foreign key". But for Performance Table, Primary Key Roll_No of Students Table can be Foreign Key." Check in above statement I said "Primary Key Roll_No of Students Table" - you didn't get this?
23rd Oct 2019, 2:04 PM
A͢J
A͢J - avatar
+ 3
Ipang with group by it gives 5 rows but without group by I don't know what will it gives because I'm assuming without group by statement error will be generated
22nd Oct 2019, 8:31 AM
Preity
Preity - avatar
+ 3
AJ || ANANT || AC || ANANY || AY Then help me understand your previous reply?
22nd Oct 2019, 9:05 AM
Ipang
+ 3
A J Primary key should never have duplicates. What can have duplicates are foreign key in other tables that references the primary key. In this case Students.Roll_no is primary key, each record has unique value. While Performance.Roll_no is a foreign key that references Students.Roll_no. You cannot say primary key can contain duplicate in whichever table, because it is only a foreign key that can have duplicates in the tables, not the table's primary key. "But for other table Primary key can be foreign key". How can that be?. A column is said a foreign key when its data references/looks up to another table. How can a column be primary key when it references other table's column?
23rd Oct 2019, 6:40 AM
Ipang
+ 2
Ipang if we do Cartesian product in above query like full join then too the same result will be there I'll try and let you know about that
22nd Oct 2019, 8:59 AM
Preity
Preity - avatar
+ 2
Ipang I agree Primary Key never have duplicate. But you still didn't understand my reply. I said Primary Key of Student table can have duplicate records in Performance Table but for Performance table Primary Key of Student table is Foreign Key. So Roll_No in Performance Table is Foreign Key which refers The table Students in which Roll_No is Primary Key. Now understood? Or still confusion?
23rd Oct 2019, 10:44 AM
A͢J
A͢J - avatar
+ 2
Ipang I was not saying that Roll_No in Performance Table is Primary Key. Let me explain this line :- "But for other table Primary key can be foreign key". But for Performance Table, Primary Key Roll_No of Students Table can be Foreign Key.
23rd Oct 2019, 10:59 AM
A͢J
A͢J - avatar
+ 2
Rafet Eyup Wrong place.
23rd Oct 2019, 11:56 AM
A͢J
A͢J - avatar
+ 1
A J The way you wrote your explanation may mislead those who doesn't know to believe that primary key can.have duplicate data. "But for Performance table, Primary key Roll_no of Students Table can be Foreign Key." But for Performance table, the Performance.Roll_no column is a foreign key that references the Students.Roll_no column. And the Students.Roll_no column is the Students table primary key, it is not a foreign key.
23rd Oct 2019, 12:47 PM
Ipang
+ 1
A J I already read that, however as I said, the way you wrote the explanation can be misleading, especially for those who didn't know.
23rd Oct 2019, 2:32 PM
Ipang
+ 1
A J Please understand, none of what I said was pointed at you. Just how the explanation was written that's all. I got nothing against you and I meant no offense nor (as some said or think) disrespect. And it was a good discussion indeed. Thanks bro ✌
23rd Oct 2019, 2:45 PM
Ipang
0
Query will not work if you remove group by. Try once. It may give error.
21st Oct 2019, 8:43 PM
A͢J
A͢J - avatar
0
AJ || ANANT || AC || ANANY || AY do you have tried that removing last line from query. As there are roll number by which query can be access?
21st Oct 2019, 8:47 PM
Preity
Preity - avatar
0
I am not using system this time but I know that it can give error.
21st Oct 2019, 8:48 PM
A͢J
A͢J - avatar