join - Double results MYSQL query (Drupal database) -
i'm trying sql result want join fields users (from drupal database). query looks this:
select * users left outer join field_data_field_wekelijkse_newsletter on users.uid = field_data_field_wekelijkse_newsletter.entity_id left outer join field_data_field_woonplaats on users.uid = field_data_field_woonplaats.entity_id left outer join field_data_field_naam on users.uid = field_data_field_naam.entity_id
i have 2 problems:
- i double results (usernames)
- the values "field_data_field_wekelijkse_newsletter" different within double results.
can me write query?
without knowing data model, , going off naming of columns, possible results not duplicates after all. if users can subscribe more 1 newsletter, perhaps happening. returning of fields every table join
on. if provide more information such schema definitions, column names, etcetera, can give more precise answer.
in addition, can offer few styling tips in regards writing sql!
use newlines , tabs, write queries developer coming in behind you! readable queriers best (and bug free) queries.
use aliases. typically, treat aliases similar variable names: keep them meaningful , short. if cannot create meaningful, short alias table, use table's initials (for table names such field_data_field_woonplaats, difficult create simple alias! consider renaming)
nomenclature everything! name tables, columns, views, indexes, triggers, keys, everything, (and other developers) can remember them , able grasp , understand kind of object represent (the data hold).
use semicolons terminate statements.
select * users u left outer join field_data_field_wekelijkse_newsletter fdfwn on u.uid = fdfwn.entity_id left outer join field_data_field_woonplaats fdfw on u.uid = fdfwn.entity_id left outer join field_data_field_naam fdfn on u.uid = fdfn.entity_id;
Comments
Post a Comment