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:

  1. i double results (usernames)
  2. 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!

  1. use newlines , tabs, write queries developer coming in behind you! readable queriers best (and bug free) queries.

  2. 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)

  3. 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).

  4. 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

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -