mysql query to concat information from 3 tables - getting incorrect result count
Posted
by
iPfaffy
on Stack Overflow
See other posts from Stack Overflow
or by iPfaffy
Published on 2012-07-11T15:12:08Z
Indexed on
2012/07/11
15:15 UTC
Read the original article
Hit count: 173
I have 3 tables in my database.
- ab_contacts
- id
- first_name
- last_name
- addressbook_id
- ab_addressbooks
- name
- id
- co_comments
- id
- link_id
- comment
I'd like to create a query that will let me select all the contacts and comments related to them in a given addressbook.
To select all the people in a given addressbook, I can use:
select count(*) from ab_contacts where addressbook_id = '50';
This returns 8152 people.
However, when I run my query:
select ab_contacts.first_name, ab_contacts.last_name, ab_contacts.email,
ab_addressbooks.name, co_comments.comments
from ab_contacts
JOIN ab_addressbooks ON (ab_contacts.addressbook_id = ab_addressbooks.id)
JOIN co_comments ON (ab_contacts.id = co_comments.link_id)
WHERE ab_contacts.addressbook_id = '50';`
the format works, but I only get 1045 results. I'm sure there is something I am missing, but I cannot figure it out. Any help would be greatly appreciated.
© Stack Overflow or respective owner