Share via

Consulta de SQL union

Ruben Dario Lezcano Salinas 0 Reputation points
2023-05-30T19:27:36.81+00:00

Buenas tardes

Necesito obtener una consulta donde quiero unir la tabla de clientes con la de pedidos.

Además de eso tiene que mostrarme los pedidos realizados el día de hoy en la consulta; tengo esta consulta pero no me muestra el nombre me da un error

select cod_cliente, nombre_cliente from clientes
union all
select cod_cliente, fecha_pedido from pedidos where fecha_pedido='2022-05-30'
SQL Server | Other
SQL Server | Other

Additional SQL Server features and topics not covered by specific categories


1 answer

Sort by: Most helpful
  1. Erland Sommarskog 134.7K Reputation points MVP Volunteer Moderator
    2023-05-30T21:39:34.0366667+00:00

    El lenguaje de es forum es inglese.

    Non solo decir "me da un error", mas por favor, incluye en mensaje de error.

    Puedo advinar: el tipo de nombre_cliente es (n)varchar, y el tipo de fecha_pedido es date. Tiene que todo los valores en un colon haber el mismo tipo, Mas un nom non es un fecha.

    Creo que esta unconsulta es mejor:

    SELECT c.cod_cliente, c.nombre_cliente, p.fecha_pedido
    FROM  cod_clients c
    JOIN  pedidos p ON c.cod_cliente = p.cod_cliente
    WHERE p.fecha_pedido = '2022-05-30'
    
    
    
    

    This is an English-language forum.

    Don't just say "gives me an error", but please include the error message-

    I can guess: the data type of nombre_client is (n)varchar and the type of fecha_pedido is date. All values in a column must be of the same data type, But a name is not a date.

    I think the query above is a better choice.

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.