Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Help with query

Author  Topic 

laurillo87
Starting Member

4 Posts

Posted - 2014-10-01 : 10:06:06
Hello,

Here is my problem, i try to do a query with two tables, MKTG_USER and MKTG_REQUERIMIENTOS.

my inner join is

MKTG_USER ON MKTG_REQUERIMIENTOS.ID_USER = MKTG_USER.ID_USUARIO AND MKTG_REQUERIMIENTOS.ID_CLIENTE = MKTG_USER.ID_USUARIO

and that dont get any data, in MKTG_USER.ID_USUARIO is PK,
MKTG_REQUERIMIENTOS.ID_USER is FK and MKTG_REQUERIMIENTOS.ID_CLIENTE is FK

the RS of Tables is here



[url]http://imageshack.com/f/hjKyYVm9p[/url]

Hope can help me.

djj55
Constraint Violating Yak Guru

352 Posts

Posted - 2014-10-01 : 11:47:02
The only way this will return anything is if MKTG_REQUERIMIENTOS.ID_USER = MKTG_REQUERIMIENTOS.ID_CLIENTE
If MKTG_USER is to be used for two different reasons then it would need to be linked twice

djj
Go to Top of Page

laurillo87
Starting Member

4 Posts

Posted - 2014-10-01 : 12:04:07
quote:
Originally posted by djj55

The only way this will return anything is if MKTG_REQUERIMIENTOS.ID_USER = MKTG_REQUERIMIENTOS.ID_CLIENTE
If MKTG_USER is to be used for two different reasons then it would need to be linked twice

djj



thank you djj

ure right, i linked twice, there is a the solution

SELECT T2.NOM_USUARIO Vendedor, T3.NOM_USUARIO Cliente FROM MKTG_REQUERIMIENTOS T1
INNER JOIN MKTG_USER T2 ON T2.ID_USUARIO = T1.ID_USER
INNER JOIN MKTG_USER T3 ON T3.ID_USUARIO = T1.ID_CLIENTE

Here is the query result

Vendedor Cliente
Luis Fabiola

Go to Top of Page
   

- Advertisement -