+ 1

Why(in mysql) does the table i want to print out get longer and longer, even tho the number of values are the same ?

3rd Jan 2023, 10:40 PM
Lenoname
7 Réponses
+ 5
The problem is that you are adding more lines to each table every time when you run the whole script. The second time you should already see some errors in the DBMS log, that table creation failed because already exists. You should only ever run "create table" once, and "insert" whenever you want to add new lines. Run the "select" separately, as many times as you want. You can fix this by deleting your tables and start over. You could add these two lines to the beginning: DROP TABLE student; DROP TABLE teacher;
4th Jan 2023, 6:06 AM
Tibor Santa
Tibor Santa - avatar
+ 2
I suppose that it has to do with record management in the DB engine. As records are deleted, updated and created, the DB engine does not necessarily keep the data contiguous. It may use whatever record location is optimal. Often this leaves unoccupied spaces between records in the file and it writes to the end of the file, expanding its size. This is not a bad thing for an active DB, because at some point one of those unoccupied spaces might be the most efficient place to store something instead of expanding the file again. After some time the file might reach its approximate steady state size with a good balance of unused space for changes.
4th Jan 2023, 12:40 AM
Brian
Brian - avatar
+ 2
Lenoname this looks like a different issue than what I first thought you were asking about. Are you querying from two tables? Depending on how your query is written, you might be getting a copy of each record in table1 for every record in table2. Can you show the query you are using and explain the results you are trying to get?
4th Jan 2023, 1:17 AM
Brian
Brian - avatar
+ 2
Please share table structure to have a clearer view of the problem. Did you mean to say those duplicate records came out of nowhere? did you implement any restriction for insert operation, like unique name or something?
4th Jan 2023, 1:20 AM
Ipang
+ 1
You need to set a unique key column and pull for a distinct value
5th Jan 2023, 8:28 PM
Brad
0
ok how do i fix it?this is whats getting printed:(cant copy paste the table output but looks something like this) , i want idris for example to be printed once id,studentname_,class,studentid,name_,age,class(values at the top) '12', 'Idris', '1', '1', 'Ali', '40', '1' '8', 'Idris', '1', '1', 'Ali', '40', '1' '4', 'Idris', '1', '1', 'Ali', '40', '1' '11', 'Hamed', '4', '2', 'Reza', '30', '4' '7', 'Hamed', '4', '2', 'Reza', '30', '4' '3', 'Hamed', '4', '2', 'Reza', '30', '4' '10', 'Hosein', '3', '3', 'Yosef', '50', '3' '2', 'Hosein', '3', '3', 'Yosef', '50', '3' '9', 'Hasan', '2', '4', 'Ibrahim', '60', '2' '5', 'Hasan', '2', '4', 'Ibrahim', '60', '2' '1', 'Hasan', '2', '4', 'Ibrahim', '60', '2' '12', 'Idris', '1', '5', 'Ali', '40', '1' '8', 'Idris', '1', '5', 'Ali', '40', '1' '4', 'Idris', '1', '5', 'Ali', '40', '1' '9', 'Hasan', '2', '6', 'Reza', '30', '2' '5', 'Hasan', '2', '6', 'Reza', '30', '2' '1', 'Hasan', '2', '6', 'Reza', '30', '2' '10', 'Hosein', '3', '7', 'Yosef', '50', '3' '2', 'Hosein', '3', '7', 'Yosef', '50', '3' '9', 'Hasan', '2', '8', 'Ibrahim', '60', '2' '5', 'Hasan', '2', '8', 'Ibrahim', '60', '2' '1', 'Hasan', '2', '8', 'Ibrahim', '60', '2' '12', 'Idris', '1', '9', 'Ali', '40', '1' '8', 'Idris', '1', '9', 'Ali', '40', '1' '4', 'Idris', '1', '9', 'Ali', '40', '1' '9', 'Hasan', '2', '10', 'Reza', '30', '2' '5', 'Hasan', '2', '10', 'Reza', '30', '2' '1', 'Hasan', '2', '10', 'Reza', '30', '2' '10', 'Hosein', '3', '11', 'Yosef', '50', '3' '2', 'Hosein', '3', '11', 'Yosef', '50', '3' '9', 'Hasan', '2', '12', 'Ibrahim', '60', '2' '5', 'Hasan', '2', '12', 'Ibrahim', '60', '2' '1', 'Hasan', '2', '12', 'Ibrahim', '60', '2'
4th Jan 2023, 12:57 AM
Lenoname