Re: Retrieve fields with similar values from 2 tables?



Erwin Moller wrote:

no.mail.pls wrote:

Hiya,

How do i retreive fields with similar values from 2 tables?

I tried to use
(1) "SELECT * FROM $table1 as o , $table2 as p WHERE o.name like
'%p.name%'";
but it retrieves nothing at all.

(2) "SELECT * FROM $table1 as o , $table2 as p WHERE o.name like p.name";
will retrieve exact matches only, but this is not what i want.

(3) SELECT * FROM $table1 as o , $table2 as p WHERE o.name LIKE
CONCAT('%', p.name, '%');
will retrieve exact matches only.

Any advice will be appreciated.

Hi,

I never saw LIKE used in that way ever before, and am unsure if that is
possible.
I only used/saw LIKE with a literal string, not a dynamic construct, like
yours, joined on another table.
I would advise you to dive into the documentation for your version of mysql,
to first check if it is allowed anyway.

If it is not allowed: solve the problem programmatically. Get the table into
your scriptingenvironment and solve the join in there.

But once again: I could be completely wrong, and maybe it IS possible in
mysql.

Regards,
Erwin Moller


PostScript: i posted the above in mysql groups, but problem remains, so am
trying my luck here.

TIA


I would probably do something like in PHP:

psuedo-code:


select name from table2;
while values
select * from table1 where name like '%$table2name%'
do more stuff... with second result set...



.



Relevant Pages

  • Re: Retrieve fields with similar values from 2 tables?
    ... Erwin Moller wrote: ... How do i retreive fields with similar values from 2 tables? ... will retrieve exact matches only, but this is not what i want. ... I would advise you to dive into the documentation for your version of mysql, ...
    (comp.lang.php)
  • Re: Retrieve fields with similar values from 2 tables?
    ... How do i retreive fields with similar values from 2 tables? ... will retrieve exact matches only, but this is not what i want. ... I would advise you to dive into the documentation for your version of mysql, ...
    (comp.lang.php)
  • Retrieve fields with similar values from 2 tables?
    ... How do i retreive fields with similar values from 2 tables? ... will retrieve exact matches only, but this is not what i want. ... trying my luck here. ... TIA ...
    (comp.lang.php)