Jump to content

Joining one row from a one to many join


khaos337

Recommended Posts

I'm sure this is a simple solution, but I have been searching for quite some time and can't seem to find a good answer. Basically I have a table with client information, and another table with notes on the client. The table with the notes has 3 columns, clientID which is a foreign key relating the note to the client table, timestamp which shows when the note was written, and note which holds the note text. I want to be able to display a list of clients with only the most recent note (using the timestamp field) displayed. If I do something like this:

SELECT c.*, cat.color, cat.name AS catname, n.note, n.timestampFROM client cLEFT JOIN category cat ON cat.ID = c.categoryLEFT JOIN notes n ON n.clientID = c.IDWHERE c.complete = 0

it returns duplicate client records for each note. What is the best way of solving this?

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...