SQL Select inner join


I have this problem that according to me I made a query to get only one answer row, but for some reason I get the same record several times, can someone tell me what I'm doing wrong?

  [Nombre de Obra],
  Estado =
  case estatus
when '0'
then 'Falta número de registro por el IMSS'
when '1'
then CONVERT(varchar(10), ob.[Número de registro de obra])

ob.[Registro Patronal DV], [Nombre, denomicacion o razon social] patron,

    calle + ' ', [numero exterior] + ' ', [numero interior] + ' ',
    colonia + ' ',
    municipiodelegacion + ' /',
    codigopostal + ' ',
    localidad + ' /',
  ) Ubicación

  , st2.[Herramienta y equipo], st2.[Costo directo del análisis de precios unitarios], st2.[Costos indirectos, utilidad y financiamiento], st2.[Días pagados], st2.[Importe presupuestado(sin IVA)], st2.[Mano de obra], st2.Materiales

from ObrasSatic ob
inner join saticF2 st2
on st2.[Número de registro de obra] = ob.[Número de registro de obra]
where ob.id_obra = 2
asked by E.Rawrdríguez.Ophanim 17.10.2018 в 20:02

2 answers


You can solve it using SQL SELECT DISTINCT Statement Something like that (obviously adding the join and everything necessary for your case):

SELECT DISTINCT [Nombre de Obra] FROM ObrasSatic.

For more info on "DISTINCT" click here

I hope it helps you. Greetings!

answered by 17.10.2018 / 20:20

If it's how I'm imagining it, you need to put the instruction "GROUP BY", so that you can group the records when they are the same, try to group them by the name of the work or by the state.

Something similar to this:

SELECT * FROM ObrasSatic WHERE id_obra = 2 GROUP BY Nombre de Obra

and with that I should only show you one row.

answered by 17.10.2018 в 20:11