给定这两个表:
打印配置文件:
idprintprofile | empresa | remoteaddress
----------------+---------+---------------
6 | PDF |
3 | HPR |
2 | GAM |
5 | TEST |
7 | TEST | 192.168.0.100
和
研究印刷品
idstudyprint | empresa | remoteaddress
--------------+---------+---------------
12162 | TEST |
12167 | GAM |
12165 | GAM |
12449 | TEST | 192.168.0.100
I want to join these 和 get this:
idstudyprint | empresa | idprintprofile | remoteaddress
--------------+---------+----------------+---------------
12449 | TEST | 7 | 192.168.0.100
12167 | GAM | 2 |
12165 | GAM | 2 |
12162 | TEST | 5 |
我提出的第一个问题是:
select sp.idstudyprint, sp.empresa, pp.idprintprofile, sp.remoteaddress from studyprint sp join printprofiles pp on pp.empresa=sp.empresa where pp.remoteaddress = sp.remoteaddress or(pp.remoteaddress = '') order by sp.created desc;
结果如下:
idstudyprint | empresa | idprintprofile | remoteaddress
--------------+---------+----------------+---------------
12449 | TEST | 5 | 192.168.0.100
12449 | TEST | 7 | 192.168.0.100
12167 | GAM | 2 |
12165 | GAM | 2 |
12162 | TEST | 5 |
如您所见,idstudyprint = 12449重复,正确的应该是带有idprintprofile = 7的。