Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

298
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda