开发者

fake columns with union and two inner joins?

i've got this query:

SELECT * FROM (
(SELECT ACCOUNTS.INSTALLTIME, ACCOUNTS.HONAME, ACCOUNTS.ADDRESS, ACCOUNTS.CITY, ACCOUNTS.STATE, ACCOUNTS.ZIP, ACCOUNTS.JOBNUMBER, ACCOUNTS.INSTALLDATE, ACCOUNTS.RESULT, ACCOUNTS.NOTES, ACCOUNTS.SMNOTES, technicians.technumber, technicians.boardplacing 
FROM ACCOUNTS 
INNER JOIN technicians ON ACCOUNTS.INSTALLER = technicians.technumber) 
UNION 
(SELECT service.servicetime, service.Customername, service.address, service.city, service.state, service.zip, service.ID, service.serviceday, service.result, service.servicenotes, service.board, technicians.technumber, technicians.boardplacing
FROM service 
INNER JOIN technicians ON service.technician= technicians.technumber)
) as t WHERE t.INSTALLDATE = '$date' ORDER BY t.boardplacing

is there any way I can make a query similar to:

SELECT * FROM (
(SELECT ACCOUNTS.INSTALLTIME, ACCOUNTS.HONAME, ACCOUNTS.ADDRESS, ACCOUNTS.CITY, ACCOUNTS.STATE, ACCOUNTS.ZIP, ACCOUNTS.JOBNUMBER, ACCOUNTS.INSTALLDATE, ACCOUNTS.RESULT, ACCOUNTS.NOTES, ACCOUNTS.SMNOTES, '' as priority, ACCOUNTS.PAFS, ACCOUNTS.upsell, ACCOUNTS.TERM, ACCOUNTS.MMRUPGRADE, ACCOUNTS.WARRANTY, ACCOUNTS.EFT, technicians.technumber, technicians.boardplacing 
FROM ACCOUNTS 
IN开发者_开发问答NER JOIN technicians ON ACCOUNTS.INSTALLER = technicians.technumber) 
UNION 
(SELECT service.servicetime, service.Customername, service.address, service.city, service.state, service.zip, service.ID, service.serviceday, service.result, service.servicenotes, service.board, '', '', '', '', '', '', technicians.technumber, technicians.boardplacing
FROM service 
INNER JOIN technicians ON service.technician= technicians.technumber)
) as t WHERE t.INSTALLDATE = '$date' ORDER BY t.boardplacing

basically i need fake columns in my union. is there any way to pull that off with the joins? is there some other better way to do this?


When I am writing a union query and need "fake" or "dummy" columns, I just use:

NULL AS Fake

So the whole query will look something like this;

SELECT A.CHEESE, A.BREAD, A.GARLIC, A.COST
FROM ACHEESETABLE A
WHERE A.BREAD = WHEAT

UNION ALL

SELECT NULL AS CHEESE, B.BREAD, NULL AS GARLIC, B.COST
FROM BCHEESYTABLE B
WHERE B.COST > 15 

This way both queries have a CHEESE and GARLIC column, but BCHEESYTABLE does not contain the columns, CHEESE or GARLIC. Doing it like this also allows different WHERE criteria for both queries, so in essence it is possible to have two different record population in the same query.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜