Jakir00
Jakir00

Reputation: 2073

MySQL: Table entry representing all 'ids'?

I have a single value in a table that I want selected every time a query is made on the table.

Let me break is down.

I have the following entry: enter image description here

Instead of making a new entry for every different user_id, can I use some kind is primitive to represent ALL user_ids instead of specific ids? Example below: enter image description here

For reasons that I would rather not take the time to explain, this is what I need. Is there any way to do this?

Thanks in advance!

Upvotes: 0

Views: 52

Answers (1)

Naltharial
Naltharial

Reputation: 2152

If I'm correct in assuming that that means you want tag_id linked to every user_id (as some sort of a catch-all clause), you have a few ways of going about it. Depending on your application, you can simply request it to add a row for tag_id = 1 whenever you add a user. If you would, however, want to do it in a single row, well ... it kind of misrepresents the relational model. You could, presumably use the NULL special "value" (essentially, declare it without a value) and then check in your application logic with

WHERE user_id = [uid] OR user_id IS NULL

or some such. I'd prefer keeping the relations intact with the former approach, however; you lose foreign keys (although using NULL won't violate the constraint) and similar constraints if you don't.

Upvotes: 1

Related Questions