Jump to content

how to combine two queries


ballouta

Recommended Posts

Hello

 

I have this query and it is working well:

$data = mysql_query("
	SELECT `title`, `body`, 'condoms_en' as REF FROM `condoms_en`
UNION
	SELECT `title`, `body`, 'discr_en' as REF FROM `discr_en`
UNION
	SELECT `title`, `body`, 'diseases_en' as REF FROM `diseases_en`
UNION
	SELECT `title`, `body`, 'express_en' as REF FROM `express_en`
UNION
	SELECT `title`, `body`, 'gender_en' as REF FROM `gender_en`
UNION
	SELECT `title`, `body`, 'get_informed_en' as REF FROM `get_informed_en`
UNION
	SELECT `title`, `body`, 'get_tested_en' as REF FROM `get_tested_en`
UNION
	SELECT `title`, `body`, 'newly_en' as REF FROM `newly_en`
UNION
	SELECT `title`, `body`, 'news_hiv_en' as REF FROM `news_hiv_en`
UNION
	SELECT `title`, `body`, 'nutrition_en' as REF FROM `nutrition_en`
UNION
	SELECT `title`, `body`, 'phdp_en' as REF FROM `phdp_en`
UNION
	SELECT `title`, `body`, 'press' as REF FROM `press`
UNION
	SELECT `title`, `body`, 'r_o_en' as REF FROM `r_o_en`
UNION
	SELECT `title`, `body`, 'stats_en' as REF FROM `stats_en`
UNION
	SELECT `title`, `body`, 'stigma_en' as REF FROM `stigma_en`
UNION
	SELECT `title`, `body`, 'think_news_en' as REF FROM `think_news_en`
UNION
	SELECT `title`, `body`, 'think_reports' as REF FROM `think_reports`
UNION
	SELECT `title`, `body`, 'treatment_en' as REF FROM `treatment_en`
where`title` like '%$kw%' OR `body` like '%$kw%'") or die(mysql_error());
$rows = mysql_num_rows($data);

 

I need to add to the same query this part:

SELECT `cont`, 'about_us_en' as REF FROM `about_us_en`
UNION
	SELECT `que`,`ans`, 'faq_en' as REF FROM `faq_en`
UNION
	SELECT `orga`, `lnk`, 'links_en' as REF FROM `links_en`
UNION
	SELECT `title`, `desc`, 'publications' as REF FROM `publications`

 

IF I add this part as is, I get an error saying that the select has different columns.

 

Please Help and how do I modify the where if they are combined?!

 

Thank you

Link to comment
Share on other sites

I added the ' ' , i dont have syntax error now BUT there's smthg wrong with the result

 

The result came in three columns, cont / about_us_en / REF

 

note that about_us_en is a table name.

 

I also need to figure out how I should modify the Where to look in the corresponding columns of the second part

 

Thanks

SELECT `cont`, 'about_us_en', '' as REF FROM `about_us_en`
UNION
	SELECT `que`,`ans`, 'faq_en' as REF FROM `faq_en`
UNION
	SELECT `orga`, `lnk`, 'links_en' as REF FROM `links_en`
UNION
	SELECT `title`, `desc`, 'publications' as REF FROM `publications`
UNION
SELECT `title`, `body`, 'condoms_en' as REF FROM `condoms_en`
UNION
	SELECT `title`, `body`, 'discr_en' as REF FROM `discr_en`
UNION
	SELECT `title`, `body`, 'diseases_en' as REF FROM `diseases_en`
UNION
	SELECT `title`, `body`, 'express_en' as REF FROM `express_en`
UNION
	SELECT `title`, `body`, 'gender_en' as REF FROM `gender_en`
UNION
	SELECT `title`, `body`, 'get_informed_en' as REF FROM `get_informed_en`
UNION
	SELECT `title`, `body`, 'get_tested_en' as REF FROM `get_tested_en`
UNION
	SELECT `title`, `body`, 'newly_en' as REF FROM `newly_en`
UNION
	SELECT `title`, `body`, 'news_hiv_en' as REF FROM `news_hiv_en`
UNION
	SELECT `title`, `body`, 'nutrition_en' as REF FROM `nutrition_en`
UNION
	SELECT `title`, `body`, 'phdp_en' as REF FROM `phdp_en`
UNION
	SELECT `title`, `body`, 'press' as REF FROM `press`
UNION
	SELECT `title`, `body`, 'r_o_en' as REF FROM `r_o_en`
UNION
	SELECT `title`, `body`, 'stats_en' as REF FROM `stats_en`
UNION
	SELECT `title`, `body`, 'stigma_en' as REF FROM `stigma_en`
UNION
	SELECT `title`, `body`, 'think_news_en' as REF FROM `think_news_en`
UNION
	SELECT `title`, `body`, 'think_reports' as REF FROM `think_reports`
UNION
	SELECT `title`, `body`, 'treatment_en' as REF FROM `treatment_en`
where`title` like '%$kw%' OR `body` like '%$kw%'

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.