如果我问一下一下一下我们安协办的桌子,我可以进入如下阶段:
SELECT * FROM ORDERS
WHERE ITEM_NAME = Fancy Pants
在本次询问的结果中,我可以得出以下结论:
----------------------------------------------------------------------
ORDER_ID WAIST First_Name Email
----------------------------------------------------------------------
001 32 Jason j-diddy[at]some-thing.com
005 28 Pip pirrip[at]british-mail.com
007 28 HAL9000 olhal[at]hot-mail.com
现在,我也希望从一个不同的表格中提取信息:
SELECT * FROM PRODUCTS WHERE ITEM_NAME = Fancy Pants
------------------------------------------
PRODUCT_ID Product Prod_Desc
------------------------------------------
008 Fancy Pants Really fancy.
In the end, however, I m actually wanting to condense these records into one row via SQL query:
-----------------------------------------------------------------------------
PRODUCT ORDER_Merged First_Name_Merged Email_Merged
-----------------------------------------------------------------------------
Fancy Pants 001,005,007 Jason,Pip,Hal9000 j-di[...].com, pirrip[...].com
Anyway, that s how it would look. What I can t figure out is what that "merge" query would look like.
不幸的是,我在这里的搜索使我能够取得PHP的成果。 我已经找到了两项成果:.merging into CSV rows through,但我认为,在我的设想中,这些结果不会奏效。
任何见解将一如既往地受到高度赞赏。
UPDATE:
Ah, Sees out the STUFF
and FOR XML
functions were exactly what I need. 感谢大家!
Select
A.name,
stuff((
select , + B.address
from Addresses B
WHERE A.id=B.name_id
for xml path( )),1,1, )
From Names A