mysql table field values are hidden - why? - mysql

I am seeing this behavior on Windows 7 - mysql v5.6.17. When I try to view table records, the field with auto incrementing primary key (here it is the column with 'id') do not show values in all rows, but those values actually were populated after loading them from a data file. My initial thought was some of the values in ID column were missing, but they are not!
If I query individual row, then it shows the value in id column. Is this a normal behavior? Is there a better way to display table records?
Please see the image enclosed below.

The data certainly appears corrupted.
An 'uncorrupted' result might look like this...
+----+-------------+-----+-----+-------+
| id | PlateNumber | Row | Col | Orf |
+----+-------------+-----+-----+-------+
| 1 | 1 | A | 1 | Empty |
| 2 | etc... | | | |

Related

how to use where caluse on primary key? [duplicate]

This question already has an answer here:
Query Distinct values from a multi-valued column
(1 answer)
Closed 5 years ago.
i'm developing a quiz website. In my database, I need a table which shows
reported quiz errors. It should look like this:
______________________________________________________________________
|key| quiz_number | who_reported_this_error | reported_number |
-----------------------------------------------------------------------
| 1 | 5 | goid482,saiai10,hahakaka | 3 |
-----------------------------------------------------------------------
| 2 | 3 | fiiai55,kihogi84 | 1 |
-----------------------------------------------------------------------
If a user named hanabi reported an error about quiz number 5,
first I need to check the who_reported_this_error column because
I don't want for a user to report same error twice. If the user 'hanabi' doesn't exist in "who_reported_this_error" column I should update row 1.
Now for my problem. I want to find a row which I should update with a key column, and the key column's number should automatically increased. But I know that I can't use a WHERE clause on this primary key. Hhow can I solve this problem?
The problem is with the table schema. NEVER store comma-separated data in a single column. You should structure the table to look more like this:
____________________________________________
|key| quiz_number | who_reported_this_error |
────────────────────────────────────────────
| 1 | 5 | goid482 |
---------------------------------------------
| 2 | 3 | fiiai55 |
---------------------------------------------
| 3 | 5 | saiai10 |
---------------------------------------------
| 4 | 5 | hahakaka |
---------------------------------------------
| 5 | 3 | kihogi84 |
--------------------------------------------
You might also want a timestamp column on this table. Then, put a UNIQUE constraint on the quiz_number and who_reported_this_error columns to prevent the duplicates.
If you later need to see everyone who reported errors for quiz 5 in the same record, use MySql's group_concat() function to build that information on the fly. Just don't store the data that way.
The key column has nothing to do with this question. You certainly can use your primary key in a WHERE clause. It just won't help you in this case because that data isn't relevant to the problem at hand.

MySQL: Show all rows with same column value one after the other with the column value appearing only once

I have a table with columns:
ResourceId | Reason
I have 4 rows with values as follows
2884 | irrelevant
3441 | irrelevant
2884 | incorrect
1234 | incorrect
I want the data to appear something like this:-
2884 | irrelevant
| incorrect
3441 | irrelevant
1234 | incorrect
i.e. I want all the rows with similar ResourceId to appear together as a group but I only want to display the ResourceId for the first row. How can I write a query for this?

Find the ranking for a row with multiple values separated by a comma in mysql

I have a database in mysql which has three rows, these rows has concatenated multiples values(values separated by a comma) already in it. I want to strike the rank using find_in_set function or any better function to get the positions.
Table
id | NUMBERS |
1 | 30,40,10 |
2 | 58,29,21 |
3 | 18,25,51 |
I want to rank each row in this format
id | NUMBERS | POSITION |
1 | 30,40,10 | 2,1,3 |
2 | 58,29,21 | 1,2,3 |
3 | 18,25,51 | 3,2,1 |
I Know the data representation and structure is wrong, but the data i have currently is made like the above and has a lot of data in it, meaning changing the structure would take me a lot of time, although I would change it later.
I need a workaround idea as to how to do this. I would be grateful for your support thanks.

Defining queries around a designed database

I have a database which contains a lot of data and although I was not involved in setting it up it is what I have to work with.
Within this database is somewhat of a lookup table. However, this table has no link to any other tables. It essentially takes the following form
ID | input | table_name |
-------------------------------------
1 | Movie | movie_tbl |
2 | Cartoon | cartoon_tbl |
3 | Animation | cartoon_tbl |
4 | Audio | audio_tbl |
5 | Picture | picture_tbl |
The table is a lot larger than the above, but the structure is as above. So what happens is someone visits my site. Here, they have an input field. Say they enter Movie then the above table is called to find the input with Movie. It then gets what table it needs to look in. I would imagine that the query would be something like
SELECT table_name FROM lookup_table WHERE input LIKE Movie;
Now that should return movie_tbl. I now know that I need to search for Movie within movie_tbl and return all the data for its row. So movie_tbl might be like this (data would be some type of data and the column names different)
ID | input | col_1 | col_2 | col_3 |
----------------------------------------------------
1 | Movie | data | data | data |
2 | Cartoon | data | data | data |
3 | Animation | data | data | data |
4 | Audio | data | data | data |
5 | Picture | data | data | data |
So now my query will be something like this
SELECT * FROM movie_tbl WHERE input LIKE Movie;
Now the tables have tens of thousands of lines of data. My real question is whether the above will be effecient or not? With the database I was given however, I do not see any other way I could do this (I cant touch the database). Is there anything I can do to make this more effecient?
Any advice appreciated
Thanks
Why are you checking for input in the 2nd table? You have already filtered the input from the first table:
SELECT table_name FROM lookup_table WHERE input LIKE Movie;
In this case you dont have to make 2 queries. Just the 2nd one should suffice. Or just having Movie data in the 2nd table and separate tables for Cartoon, Animation etc. Because then you wont be accessing the 'WHERE' clause, just:
SELECT * FROM movie_tbl;
2nd Suggestion: Use = instead of LIKE. No need for pattern matching if you know the exact input string.

Set max rows in mySQL and auto truncate

I'm wondering if MySQL supports the ability to set max rows in a table and auto truncate old entries. Let's say I have the following table and I want max rows of 5.
| ID | VALUE |
| 0 | value |
| 1 | value |
| 2 | value |
| 3 | value |
| 4 | value |
Then, another row is added, with ID 5, so I'd want ID 4 to drop and ID 5 to be added to the top of the stack.
Use a trigger. Check the count of values each time you get an insert.
You may have to map the table out to a temp folder and copy it back in with the rotated list but 5 values would make this a pretty cheap operation.