Jump to content

results from unin sql


houssam_ballout

Recommended Posts

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

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
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

Link to comment
Share on other sites

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...