houssam_ballout Posted November 12, 2007 Share Posted November 12, 2007 Hello all, I am buidling sql statment, with the union keywork, "I am doing a search for my site to search for my 2 tables . projects and news" based on the results I want to check wether the results are from the table projets or the table news to make a link based on the search criteriais there someway to do that?Thanks in advance Link to comment Share on other sites More sharing options...
Reg Edit Posted November 12, 2007 Share Posted November 12, 2007 Hello all, I am buidling sql statment, with the union keywork, "I am doing a search for my site to search for my 2 tables . projects and news" based on the results I want to check wether the results are from the table projets or the table news to make a link based on the search criteriais there someway to do that?Thanks in advanceYes (with MS SQL at least, and I assume other SQL too): in your select statement, you can just include a new column in the resultset, set to a constant which identifies the table:select 'projects' as tableid, * from projectsunionselect 'news' as tableid, * from news Link to comment Share on other sites More sharing options...
houssam_ballout Posted November 13, 2007 Author Share Posted November 13, 2007 Yes (with MS SQL at least, and I assume other SQL too): in your select statement, you can just include a new column in the resultset, set to a constant which identifies the table:select 'projects' as tableid, * from projectsunionselect 'news' as tableid, * from news but I want to differentiate between the 2, for example if there somethng called 'xyz' in news and 'xyz' in project, each one will have different hyperlink at the results page,is there someway to know from which table did the results came??? Link to comment Share on other sites More sharing options...
Reg Edit Posted November 13, 2007 Share Posted November 13, 2007 but I want to differentiate between the 2, for example if there somethng called 'xyz' in news and 'xyz' in project, each one will have different hyperlink at the results page,is there someway to know from which table did the results came???Yes, by checking the value of the tableid field.If it's still not obvious what I mean, please post your union query and I'll use that to show what I mean. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.