Find Unique Values After using UNION in select query

It was a scenario when I had to fetch data from 3 databases.

Fetching data was not tough as I had used UNION in the select query but the tough part for me was finding the distinct/unique name from all the 3 databases.

I tried different ways to fetch the distinct name from the database but somehow nothing worked as I was using UNION of  3 databases.

I came up with a simple solution of writing the UNION query in a normal way and then storing the data into an array.

After that, I have used array_unique to find the unique name from all the databases.

$sql= "select id, name from db1.users 
UNION 
select id, name from db2.users
UNION
select id, name from db3.users
GROUP BY name
";
//replace db1,db2,db3 with your database names
$res= mysql_query($sql);
$array = array();

while ($data = mysql_fetch_array($res))
{
	$name=$data['name']; //change the name of the field as per requirement
	$array[] = $name;
}	
$names = array_values( array_unique( $array ) );
$names = sort($names); //sort the field as per requirement 
//print_r($names);
foreach( $names as $information_source_name ) {
        echo $information_source_name;
        echo "<br>";
// you can also print the data in tabular format using following lines. Dont forget to add <table> tag before and
//after while loop
//echo'<tr style="background-color:#FFFFFF">';
//echo'<td>'.$information_source_name.'</td>';
// echo "</tr>";
} 
?>

Code written here is very very easy to understand. But still, if you need any explanation, put your doubts in the comment section given below 🙂

930 thoughts on “Find Unique Values After using UNION in select query

  1. Pingback: Google
  2. Pingback: 사다리사이트
  3. Pingback: 먹튀검증
  4. Pingback: 안전놀이터
  5. Pingback: bosch wvh28440
  6. Pingback: female sex toys
  7. Pingback: dual penetration
  8. Pingback: ссылка
  9. Pingback: beast tv
  10. Pingback: Strap Ons
  11. Pingback: top shop london
  12. Pingback: double sided dong
  13. Pingback: چت سکسی
  14. Pingback: 토토검증
  15. Pingback: 안전공원
  16. Pingback: Google
  17. Pingback: 토토사이트
  18. Pingback: cursos online
  19. Pingback: teen sex
  20. Pingback: seahawks
  21. Pingback: male bondage gear
  22. Pingback: Food coupons
  23. Pingback: kegel toys
  24. Pingback: latest vibrator
  25. Pingback: FIFA Coins
  26. Pingback: body wand massager
  27. Pingback: Detroit SEO
  28. Pingback: detox tea
  29. Pingback: multqa.ae
  30. Pingback: cursos gratuitos
  31. Pingback: ultimate ring
  32. Pingback: XXX
  33. Pingback: chwilówki
  34. Pingback: vibrato lesson
  35. Pingback: silver bullet egg
  36. Pingback: evolved sex toy
  37. Pingback: Porn City
  38. Pingback: glow dildo
  39. Pingback: Nerf Gun
  40. Pingback: mail order brides
  41. Pingback: detroit seo
  42. Pingback: brazzers porn
  43. Pingback: top anal sex toys
  44. Pingback: Lawn
  45. Pingback: best penis pump
  46. Pingback: anal sex toys
  47. Pingback: fun88
  48. Pingback: 188bet
  49. Pingback: blue dolphin vibe
  50. Pingback: max results pump
  51. Pingback: webcam sex
  52. Pingback: milf dating
  53. Pingback: cameras ao vivo
  54. Pingback: rencontres sexe
  55. Pingback: butt plug set
  56. Pingback: anal cleaning bag
  57. Pingback: pocket stroker
  58. Pingback: Opblaasband
  59. Pingback: Acronis Cracks
  60. Pingback: cursos gratuitos
  61. Pingback: dani fleshlight
  62. Pingback: gay cock
  63. Pingback: bullet vibe
  64. Pingback: webcambabes
  65. Pingback: webcambabes
  66. Pingback: anal play kit
  67. Pingback: double ended dildo
  68. Pingback: thruster vibe
  69. Pingback: wireless anal plug
  70. Pingback: penis stroker
  71. Pingback: sex toys
  72. Pingback: gay anal toys
  73. Pingback: top rated strapons
  74. Pingback: penis enhancement
  75. Pingback: dildo
  76. Pingback: silicone vibrator
  77. Pingback: Pornland
  78. Pingback: vibrating dildo
  79. Pingback: Photoshop Discount
  80. Pingback: fun surveys
  81. Pingback: i'm feeling good
  82. Pingback: hp 2311x driver
  83. Pingback: ярем
  84. Pingback: dildo reviews
  85. Pingback: big didlo
  86. Pingback: viagra
  87. Pingback: satta king
  88. Pingback: bullet egg
  89. Pingback: best double dildo
  90. Pingback: realistic dildo
  91. Pingback: g spot vibrator
  92. Pingback: silicone dilators
  93. Pingback: gay male toys
  94. Pingback: vibrating stroker
  95. Pingback: bondage toys
  96. Pingback: porn city
  97. Pingback: pornland
  98. Pingback: butterfly vibe
  99. Pingback: Cialis
  100. Pingback: gay men underwear
  101. Pingback: realistic dildo
  102. Pingback: best booksever
  103. Pingback: dual ended stroker
  104. Pingback: dildo reviews
  105. Pingback: bullet massager
  106. Pingback: best paddle
  107. Pingback: bondage
  108. Pingback: Barbie speelgoed
  109. Pingback: stocking lingerie
  110. Pingback: taske til hund
  111. Pingback: Roulette online
  112. Pingback: Julia Ann
  113. Pingback: bdjobs apps
  114. Pingback: Fashion Station
  115. Pingback: Fashion Station
  116. Pingback: Pool Covers
  117. Pingback: geile sex filmpjes
  118. Pingback: gratis films
  119. Pingback: pornofilmpjes
  120. Pingback: liteblue.usps.gov
  121. Pingback: zutkm
  122. Pingback: flights
  123. Pingback: penis pump review
  124. Pingback: luksus hundeseng
  125. Pingback: best nipple clamps
  126. Pingback: beeg
  127. Pingback: مساج مصر
  128. Pingback: one.walmart.com
  129. Pingback: type 1 diabetes
  130. Pingback: compte outlook
  131. Pingback: top rated vibrator
  132. Pingback: finger vibrator
  133. Pingback: podcast
  134. Pingback: situs poker
  135. Pingback: g spot stimulation
  136. Pingback: my first vibrator
  137. Pingback: blowjob
  138. Pingback: Free Funding
  139. Pingback: penis rings
  140. Pingback: daftar maxbet
  141. Pingback: cs go hacks
  142. Pingback: Hotmail login
  143. Pingback: Gmail Login
  144. Pingback: Hooligan movie
  145. Pingback: mide 675
  146. Pingback: xxx
  147. Pingback: YtMp3
  148. Pingback: male prostate toys
  149. Pingback: onewalmart.com
  150. Pingback: domain
  151. Pingback: wizkid
  152. Pingback: PPPD-780
  153. Pingback: vibrator review
  154. Pingback: anal sex toys
  155. Pingback: anal training plug
  156. Pingback: waterproof rabbit
  157. Pingback: step mom sleeping
  158. Pingback: cheap follower
  159. Pingback: seo merimbula
  160. Pingback: gay dildo videos
  161. Pingback: prepaidgiftbalance
  162. Pingback: nhdtb 305
  163. Pingback: 192.168.254.254
  164. Pingback: cawd 003
  165. Pingback: dildo with balls
  166. Pingback: buttplug
  167. Pingback: boy jockstraps
  168. Pingback: app for laptop
  169. Pingback: exotic cartridges
  170. Pingback: Boston Car Service
  171. Pingback: Minyak Kelapa
  172. Pingback: dank vapes
  173. Pingback: Family Lawyer
  174. Pingback: Vape Pens For Sale
  175. Pingback: Weed for sale
  176. Pingback: weight loss
  177. Pingback: online advertising
  178. Pingback: Modafinil Online
  179. Pingback: ABP 898
  180. Pingback: walmart wire login
  181. Pingback: my gift card site
  182. Pingback: T shirts
  183. Pingback: MEYD-525
  184. Pingback: Women clothing
  185. Pingback: 618media.com
  186. Pingback: Zion
  187. Pingback: Ioe business
  188. Pingback: Ccleaner Crack
  189. Pingback: diazepam for sale
  190. Pingback: marketing Canada
  191. Pingback: bondage gear
  192. Pingback: nipple toys
  193. Pingback: Judi Slot Online
  194. Pingback: IPX 363
  195. Pingback: walmartone.com
  196. Pingback: prostate vibrator
  197. Pingback: SEO Vancouver
  198. Pingback: pizza near me
  199. Pingback: PPPD-789
  200. Pingback: daftar joker123
  201. Pingback: realistic dildo
  202. Pingback: Escorts in Mumbai
  203. Pingback: HUNTA 653
  204. Pingback: best bullet vibe
  205. Pingback: milfgilf porn
  206. Pingback: CAWD-010
  207. Pingback: XVSR-501
  208. Pingback: sewa led
  209. Pingback: The Goat debate
  210. Pingback: عرب نار
  211. Pingback: nipple sex toys
  212. Pingback: wegmans connect
  213. Pingback: Thc vape pen
  214. Pingback: apps for pc
  215. Pingback: g spot vibrator
  216. Pingback: we-b-tv.com
  217. Pingback: hs;br
  218. Pingback: tureckie_serialy
  219. Pingback: 00-tv.com
  220. Pingback: +1+
  221. Pingback: watch
  222. Pingback: ++++++
  223. Pingback: HD-720
  224. Pingback: 2020
  225. Pingback: Video
  226. Pingback: wwin-tv.com
  227. Pingback: Web designing
  228. Pingback: MIMK 070
  229. Pingback: WANZ 898
  230. Pingback: free porn xxx
  231. Pingback: latest jobs update
  232. Pingback: app apk for pc
  233. Pingback: pc games download
  234. Pingback: thc vape juice
  235. Pingback: flexy spy
  236. Pingback: mspy erfahrung
  237. Pingback: ADN-227
  238. Pingback: double sided dildo
  239. Pingback: best bullet vibe
  240. Pingback: bullet vibe
  241. Pingback: virtual bank
  242. Pingback: Netflix
  243. Pingback: jewelry stores
  244. Pingback: percocet online
  245. Pingback: buy dbol online
  246. Pingback: pc app
  247. Pingback: Turkey smm panel
  248. Pingback: anal vibrators
  249. Pingback: Moving Pet
  250. Pingback: THC vape juice
  251. Pingback: strap on dildo
  252. Pingback: anal sex
  253. Pingback: Prestige Waterford
  254. Pingback: big dildo
  255. Pingback: viagra
  256. Pingback: buy viagra
  257. Pingback: free apk download
  258. Pingback: 1950g
  259. Pingback: propidren
  260. Pingback: wand vibrator
  261. Pingback: realistic strap on
  262. Pingback: free app download
  263. Pingback: porn
  264. Pingback: porn
  265. Pingback: cbd oil for sale
  266. Pingback: cbd for sale
  267. Pingback: cialis
  268. Pingback: viagra
  269. Pingback: stopoverdoseil.org
  270. Pingback: vibrator
  271. Pingback: convertidor mp3
  272. Pingback: Anti acne cream
  273. Pingback: top smm panel
  274. Pingback: bondage sex
  275. Pingback: love swing
  276. Pingback: disguised sex toys
  277. Pingback: bondage restraints
  278. Pingback: girth enlargement
  279. Pingback: male p spot
  280. Pingback: classic vibrator
  281. Pingback: clone a penis
  282. Pingback: سکس گروهی
  283. Pingback: Models Album
  284. Pingback: Thailand Rajabhat
  285. Pingback: viagra
  286. Pingback: viagra
  287. Pingback: viagra
  288. Pingback: viagra
  289. Pingback: viagra
  290. Pingback: viagra
  291. Pingback: viagra
  292. Pingback: viagra
  293. Pingback: robux generator
  294. Pingback: VIAGRA
  295. Pingback: nude
  296. Pingback: v bucks hack 2019
  297. Pingback: spins hack tool
  298. Pingback: VIAGRA
  299. Pingback: VIAGRA
  300. Pingback: FREE V BUCKS
  301. Pingback: sex
  302. Pingback: training anal toys
  303. Pingback: casual encounters
  304. Pingback: butt plug vibrator
  305. Pingback: subs ]] It: Chapte
  306. Pingback: free vbucks
  307. Pingback: dp dong
  308. Pingback: virtual bank
  309. Pingback: butt plugs
  310. Pingback: pleasure panty
  311. Pingback: FUCK
  312. Pingback: robux free
  313. Pingback: adsense
  314. Pingback: prostate massage
  315. Pingback: women masturbation
  316. Pingback: royal cbd
  317. Pingback: sex tube
  318. Pingback: nude
  319. Pingback: Topmediamarkt.com
  320. Pingback: casual encounters
  321. Pingback: viagra pills
  322. Pingback: powerful vibrator
  323. Pingback: pocket stroker
  324. Pingback: Microsoft Windows
  325. Pingback: streaming gratuit
  326. Pingback: porn
  327. Pingback: vibrating dildo
  328. Pingback: anal dildos
  329. Pingback: 안전놀이터
  330. Pingback: 토토메이저
  331. Pingback: 안전놀이터
  332. Pingback: movies
  333. Pingback: 바다이야기
  334. Pingback: 먹튀사이트
  335. Pingback: SPAM
  336. Pingback: free robux 2019
  337. Pingback: escort directory
  338. Pingback: movies online
  339. Pingback: karan johar
  340. Pingback: Top Movies
  341. Pingback: Movies1
  342. Pingback: vibrating dildo
  343. Pingback: 11 10 2019
  344. Pingback: dating
  345. Pingback: cozaar
  346. Pingback: anime
  347. Pingback: Bond Cleaning
  348. Pingback: cbd oil for sale
  349. Pingback: male toy kit
  350. Pingback: huge dildos
  351. Pingback: Melbourne Cleaners
  352. Pingback: nude
  353. Pingback: skelaxin
  354. Pingback: stiiizy
  355. Pingback: Infrared Cabin
  356. Pingback: Film Streaming
  357. Pingback: Threema
  358. Pingback: Innovation
  359. Pingback: MVSD 410
  360. Pingback: couple foreplay
  361. Pingback: anal vibe
  362. Pingback: Serial smotret
  363. Pingback: kinokrad
  364. Pingback: kinokrad 2020
  365. Pingback: chomnes
  366. Pingback: nasonex
  367. Pingback: porn download
  368. Pingback: full apps download
  369. Pingback: Vidalista 40mg
  370. Pingback: software informer
  371. Pingback: Amsterdam escort
  372. Pingback: Book a escort
  373. Pingback: Watch TV Shows
  374. Pingback: casino
  375. Pingback: filmy-kinokrad
  376. Pingback: kinokrad-2019
  377. Pingback: serial
  378. Pingback: HND 749
  379. Pingback: best wand massager
  380. Pingback: smart eload
  381. Pingback: thrusting vibe
  382. Pingback: ăn sáng ngon q3
  383. Pingback: Famous hunters
  384. Pingback: GENM 023
  385. Pingback: Attachakki
  386. Pingback: first dong
  387. Pingback: csu login
  388. Pingback: restaurants nearby
  389. Pingback: disvutir
  390. Pingback: cerialest.ru
  391. Pingback: Mesothelioma
  392. Pingback: YOUPORN
  393. Pingback: roblox studio
  394. Pingback: male orgasm
  395. Pingback: new sex toy
  396. Pingback: #health
  397. Pingback: descargasmix
  398. Pingback: big dildos
  399. Pingback: best dildo
  400. Pingback: double ended dildo
  401. Pingback: asmr
  402. Pingback: butt tapping asmr
  403. Pingback: cbd capsules
  404. Pingback: legoland hotel
  405. Pingback: blackhat seo links
  406. Pingback: Body Soap
  407. Pingback: 메이저놀이터
  408. Pingback: garden seeds
  409. Pingback: classic vibrator
  410. Pingback: 123movies
  411. Pingback: s&m
  412. Pingback: buy ddos service
  413. Pingback: bariatric surgery
  414. Pingback: rampant rabbit
  415. Pingback: 더킹카지노
  416. Pingback: 퍼스트카지노
  417. Pingback: 우리카지노
  418. Pingback: 코인카지노
  419. Pingback: bbq
  420. Pingback: 예스카지노
  421. Pingback: air ticket
  422. Pingback: mens pleasure toys
  423. Pingback: tryst massager
  424. Pingback: PORNHUB
  425. Pingback: FAKE NEWS
  426. Pingback: web designing
  427. Pingback: Pizza
  428. Pingback: cozaar
  429. Pingback: sex toys for men
  430. Pingback: TSUE
  431. Pingback: prowizja/prowizji
  432. Pingback: bullet vibe
  433. Pingback: fingo nubby
  434. Pingback: porn
  435. Pingback: Dog Bandanas
  436. Pingback: FREE ROBUX 2020
  437. Pingback: realistic dildo
  438. Pingback: buy phen375
  439. Pingback: clit massager
  440. Pingback: top dildos
  441. Pingback: frozen 2
  442. Pingback: Maui banyan
  443. Pingback: apps for pc,
  444. Pingback: bofilm
  445. Pingback: 1 seriya
  446. Pingback: find more info
  447. Pingback: silicone anal plug
  448. Pingback: strapon harness
  449. Pingback: VIAGRA
  450. Pingback: CHEAP VIAGRA
  451. Pingback: robux promo codes
  452. Pingback: VIAGRA
  453. Pingback: viagra men
  454. Pingback: SEO
  455. Pingback: best cbd for sleep
  456. Pingback: giày yeezy
  457. Pingback: caller divert
  458. Pingback: FREE PORN VIDEOS
  459. Pingback: Anime Batch
  460. Pingback: topedstoreusa.com
  461. Pingback: searchtempo.com.au
  462. Pingback: PORNHUB
  463. Pingback: gubnoj starosta
  464. Pingback: velichie sinonim
  465. Pingback: ammiaka udarenie
  466. Pingback: penis pumps
  467. Pingback: huge dong
  468. Pingback: vibrators
  469. Pingback: adam and eve store
  470. Pingback: adam’s dildo
  471. Pingback: CHEAP VIAGRA
  472. Pingback: biography wiki
  473. Pingback: panty vibrator
  474. Pingback: testicle ring
  475. Pingback: VIRAL SEX
  476. Pingback: bdsm sex sling
  477. Pingback: anal sex toys
  478. Pingback: prostate massager
  479. Pingback: best butt plug
  480. Pingback: best panty vibe
  481. Pingback: g spot vibrator
  482. Pingback: bunny vibrator
  483. Pingback: abuja pdp rally
  484. Pingback: CHEAP VIAGRA
  485. Pingback: smart products
  486. Pingback: ROBUX
  487. Pingback: hqcialismht.com
  488. Pingback: double dildo
  489. Pingback: bunny sex toy
  490. Pingback: puppy training
  491. Pingback: ABP 937
  492. Pingback: SSNI-668
  493. Pingback: terjemahan
  494. Pingback: eve's triple
  495. Pingback: BANNED VIAGRA
  496. Pingback: url
  497. Pingback: legionella test
  498. Pingback: 더나인카지노

Leave a Reply