A
A
alex4answ2019-12-07 13:18:24
SQL
alex4answ, 2019-12-07 13:18:24

How to get data from 2 tables under different conditions?

Good afternoon.
There are tables:
5deb7a2d0a1db897963127.png
Setting - list of settings
Setting_Value - list of settings values:

domain_id (null) // Если NULL, то настройка общая, не привязана к домену
   language_id (null) // Если NULL, то настройка общая, не привязана к языку

How do I get a list of all settings for the current domain_id and language_id?
If, for example, some can be with domain_id = null, or with language_id = null (or both columns = null at once)
That is, how not to produce redundant data, and not create copies of the same values ​​for different language_id and domain_id?
Here is an example:
The site_name (Site name) setting can be different for each domain and language
The main_page (main page ID) setting will be the same for all domains, but different for languages
, etc.
The disconnected setting (Does the domain flag is disabled), for all domains except 1 may be the same
How can I not spawn a bunch of redundant data? (although if you make copies for each language, for each domain, there will be no sampling problem)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey c0re, 2019-12-07
@alex4answ

SELECT *
  FROM setting_salue sv
  JOIN setting s ON s.id = sv.setting_id
  WHERE (sv.domain_id = DOMAIN_ID OR sv.domain_id IS NULL)
    AND (sv.language_id = LANG_ID OR sv.language_id IS NULL)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question