cyberRobot Posted January 20, 2010 Share Posted January 20, 2010 I'm using UNION to merge two resultsets. Everything works, but I trying to figure out how to add a flag to the resultset. Basically I have a table for pre-defined stakeholders and a table for other stakeholders. Since I'll be using the id from both tables and it may overlap, I would like to create a flag to indicate if its an other stakeholder or not. Here is my query so far: (SELECT id, org, type FROM stakeholders) UNION (SELECT id, orgOther, orgOtherType FROM otherStakeholders) ORDER BY type, org Here is the "stakeholders" table: idorgtype 1s1National 2s2State/Local 3s3State/Local 4s4National Here is the "otherStakeholders" table: idorgOtherorgOtherType 1other_s1National 2other_s2State/Local Note that the otherStakeholders table has been simplified...there is a reason why it's stored in a seperate table. Also, I'm using MySQL 5.0 if it matters. Link to comment https://forums.phpfreaks.com/topic/189175-adding-flags-to-resultset/ Share on other sites More sharing options...
cyberRobot Posted January 20, 2010 Author Share Posted January 20, 2010 OK, I figured out a solution: (SELECT id, org, type, CONCAT('0') AS isOther FROM stakeholders) UNION (SELECT id, orgOther, orgOtherType, CONCAT('1') FROM otherStakeholders) ORDER BY type, org If you know of a better solutions, I'm open to suggestions. Link to comment https://forums.phpfreaks.com/topic/189175-adding-flags-to-resultset/#findComment-998796 Share on other sites More sharing options...
fenway Posted January 20, 2010 Share Posted January 20, 2010 That's pretty much the only way. Link to comment https://forums.phpfreaks.com/topic/189175-adding-flags-to-resultset/#findComment-998997 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.