I am brand new here, I read a lot but i didn't have an account until now, I wonder if someone would be kind enough to help me?
I have three tables: Tasks Users Notes
Tasks and notes have a foreign key 'id' to the user table. Notes has the foreign key 'id' from the task table.
These are the queries separately:
SELECT * FROM notes WHERE taskid='id'
SELECT id, userid, taskid, nickname FROM notes WHERE taskid='id'
AND NOT userid='id'
SELECT * FROM notes WHERE taskid='id' AND userid='id
What I want to do is combine this query into one, so that I end up with Tasks and offers that match the queries above in the same table.
I tried to inner join and union all but each select statement has a different number of columns, so I am a little stuck.
What I want to end up with is all tasks plus all notes for that task where the user is the owner of the task and the note. Plus all notes for the task where the user is not the owner(only a subset of the notes info) not all fields.
Thanks in advance, if you need more info ask.
Ok here is a spread sheet with a simple example of the result:
https://docs.google.com/spreadsheets/d/1UEPCyMLGKqd0ylafUvUVquUxcZ43V3sQFKYO3SjwIGo/edit?usp=sharing
How about doing just SELECT * FROM notes WHERE taskid='id' order by userid and then doing the rest of processing in your programming language?
I found the answer anyway, it was so simple, another guy suggested I should just null the fields of one of the tables in the query Simple but now the queries work!