Query is bringing up no records

Asked by At

I am trying to create a dynamic field that displays a different value based on the current user. I have a contacts table and I want it to contain a field called contact_notes where each user can enter notes about the contacts in the table. The contact note should only display the note the current user entered for each contact. To do this I created a link table called contacts_users with these fields:

contact_id (Primary),
user_id (Primary),
contact_note

I linked contacts_users.contact_id with contacts.contact_id but I am having trouble getting the query to pull up the correct contact_note based on the current user. I tried the query below but once I add the WHERE clause, no records display. Any suggestions on what is wrong with my query?

https://pastebin.com/kKP6DZV1

SELECT
contacts.contact_id,
contacts.vendor_id,
contacts.contact,
contacts.contact_type,
contacts.title,
contacts.phone,
vendors.vendor,
vendors.msa_list,
vendors.search_words,
contacts_users.contact_note
FROM contacts
LEFT OUTER JOIN vendors ON contacts.vendor_id = vendors.vendor_id
RIGHT JOIN contacts_users ON contacts_users.contact_id = contacts.contact_id

WHERE (contacts_users.user_id = ':session.user_id') GROUP BY contacts.contact_id

0 Answers