Support the ongoing development of Laravel.io →
posted 10 years ago
Database

Hi there!

I have got two SQL issues:

  1. I need to join two tables by comparing the field tx_ard_users.uid to either tx_ard_researches.incharge or tx_ard_researches.collaborators. I'm not sure my function is correct... can you help me?

  2. The fields tx_ard_researches.incharge and tx_ard_researches.collaborators are BLOB fields in mySQL. Using LIKE is the best thing I found, but it's not correct. Do you have any better idea?


$researches = DB::table('tx_ard_researches')
	->join('tx_ard_users', function($join) {
		$join->on('tx_ard_researches.incharge', 'LIKE', "%"."tx_ard_users.uid"."%")
		->orOn('tx_ard_researches.collaborators', 'LIKE', "%"."tx_ard_users.uid"."%");
	})

        ->get();

Thank you guys for your help!

Last updated 2 years ago.
0

Why are you concatenating: "%"."tx_ard_users.uid"."%" ?

Last updated 2 years ago.
0

Hmmm... I thought I had to do it this was to have the value between %% as it is a LIKE... do you have a better idea? I'd be glad! :-D

Last updated 2 years ago.
0

Just do "%tx_ard_users.uid%" :)

Last updated 2 years ago.
0

I think that in fact you need to concatenate

...
$join->on('tx_ard_researches.incharge', 'LIKE', DB::raw( "CONCAT('%', tx_ard_users.uid, '%')
" ))...

Not sure of % and performance of this query though, depends on your needs.

Last updated 2 years ago.
0

Yes, this is right, im sorry

Last updated 2 years ago.
0

Thank you guys! You're great!

Last updated 2 years ago.
0

Great, thanks!

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.