Correct database operation to get the data desired
Ok, so I've got a MySQL database with several tables. One of the tables
(table A) has the items of most interest to me.
It has a column called type and a column called entity_id. The primary key
is something called registration_id, which is more or less irrelevant to
me currently.
Ultimately, I want to gather all items of a particular type, but which
have a unique entity_id. The only problem with this is that entity_id in
table A is NOT a unique key. It is possible to have multiple
registration_ids per entity_id.
Now, there's another table (table B) which has only a list of unique
entity_ids (that is, it is the primary key on that table), however there's
no information on the type in that table.
So with these two tables, what is the best way to get the data I want?
I was thinking some sort of way (DISTINCT) that I could use on the first
table, alone, or possibly a join of some sort (I'm still relatively new to
the concept of joins) between table A and table B, combining the entity_id
from table B with the type from table A.
What's the most efficient database operation for this for now? And should
I (eventually, not right now as I simply do not have the time, sadly)
change the database structure for greater efficiency?
If anyone needs any additional information or graphics, let me know.
No comments:
Post a Comment