Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

296
Views
How do structure this query to combine two tables based on conditions

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

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

How about doing just SELECT * FROM notes WHERE taskid='id' order by userid and then doing the rest of processing in your programming language?

over 4 years ago · Santiago Trujillo Report

0

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!

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!