473,769 Members | 6,385 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Retrieve fields with similar values from 2 tables?

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.

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

TIA
Mar 17 '06 #1
13 2203
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 programmaticall y. Get the table into
your scriptingenviro nment 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


Mar 17 '06 #2
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.

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

TIA


You've also asked this in (at least) comp.databases. mysql and
alt.comp.databa ses.mysql (where is is much more appropriate).

And please learn how to cross-post.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Mar 17 '06 #3
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 programmaticall y. Get the table into
your scriptingenviro nment 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:

select name from table2;

in a while loop

Mar 17 '06 #4
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 programmaticall y. Get the table into
your scriptingenviro nment 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...

Mar 17 '06 #5
>>> 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.
Unless you have a name that contains the string 'p.name', literally,
you won't.
(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 don't see why not.
I only used/saw LIKE with a literal string, not a dynamic construct, like
yours, joined on another table.
Granted, it may not be done that way very often, but it's possible.
I would advise you to dive into the documentation for your version of mysql,
to first check if it is allowed anyway.


I have used:
... WHERE '$email' like whitelist.patte rn;

on occasion in email filtering applications. pattern might contain
something like '%@mycustomer.c om' or '%@%.mycompany. com'. It's not
real efficient (MySQL probably has to do a patternmatch on every
row, especially if the leading character in the pattern is a %, as
it often is. But it works. And it may be much easier to use
patterns than to use lots more fixed strings and separate tables
for host, user@host, user, etc.

Also possible is:

... WHERE normalize('$ema il') like normalize(white list.pattern);

where the normalize() function converts to lower case, removes leading
and trailing spaces, removes comments, etc. This one is also likely
difficult to optimize. normalize() would either be implemented with
stored procs or be expanded inline with calls to a bunch of other
SQL functions.

Gordon L. Burditt

Mar 17 '06 #6
"Erwin Moller"
<si************ *************** *************** @spamyourself.c om> wrote in
message news:44******** *************** @news.xs4all.nl ...
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 programmaticall y. Get the table
into
your scriptingenviro nment and solve the join in there.

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

Regards,
Erwin Moller


Hiya,

Thanks for all replies.

The following solution posted by Jake works like a charm.

"Jake Krohn" <kr****@ece.cmu .edu> wrote in message
news:dv******** **@nntp.ece.cmu .edu... Try this:
SELECT * FROM table1 a, table2 b
WHERE INSTR(a.name, b.name) <> 0
Jake Krohn


The doc from mysql.com has this to say:
INSTR(str,subst r)

Returns the position of the first occurrence of substring substr in string
str. This is the same as the two-argument form of LOCATE(), except that the
order of the arguments is reversed.

mysql> SELECT INSTR('foobarba r', 'bar');
-> 4
mysql> SELECT INSTR('xbar', 'foobar');
-> 0
This function is multi-byte safe. In MySQL 3.23, this function is case
sensitive. For 4.0 on, it is case sensitive only if either argument is a
binary string.

cheers.

Mar 21 '06 #7
"Jerry Stuckle" <js*******@attg lobal.net> wrote in message
news:FO******** ************@co mcast.com...
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.

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

TIA

You've also asked this in (at least) comp.databases. mysql and
alt.comp.databa ses.mysql (where is is much more appropriate).

And please learn how to cross-post.


Pethaps to x-post or not is a choice between the devil and the deep blue
sea, even though not all of us believe in devils, and some of us love the
deep blue sea.

Tiptoeing gently among the mines in Usenet can be a tricky bizness.

cheers
Mar 21 '06 #8
no.mail.pls wrote:
"Jerry Stuckle" <js*******@attg lobal.net> wrote in message
news:FO******** ************@co mcast.com...
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.

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

TIA


You've also asked this in (at least) comp.databases. mysql and
alt.comp.data bases.mysql (where is is much more appropriate).

And please learn how to cross-post.

Pethaps to x-post or not is a choice between the devil and the deep blue
sea, even though not all of us believe in devils, and some of us love the
deep blue sea.

Tiptoeing gently among the mines in Usenet can be a tricky bizness.

cheers


And people who want answers should follow usenet conventions - which
includes cross-posting instead of multi-posting.
--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Mar 21 '06 #9
"Jerry Stuckle" <js*******@attg lobal.net> wrote in message
news:Qd******** *************** *******@comcast .com...
no.mail.pls wrote:
"Jerry Stuckle" <js*******@attg lobal.net> wrote in message
news:FO******** ************@co mcast.com...
no.mail.pl s 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.

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

TIA

You've also asked this in (at least) comp.databases. mysql and
alt.comp.dat abases.mysql (where is is much more appropriate).

And please learn how to cross-post.

Pethaps to x-post or not is a choice between the devil and the deep blue
sea, even though not all of us believe in devils, and some of us love the
deep blue sea.

Tiptoeing gently among the mines in Usenet can be a tricky bizness.

cheers

And people who want answers should follow usenet conventions - which
includes cross-posting instead of multi-posting.


Perhaps it is more accurate to say that it includes, as well as excludes,
x-posting. Sell not the devil short.

cheers


Mar 22 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
5269
by: AAVF | last post by:
Hi We have a problem with a query. An Access database links via ODBC to a UNIX server. To speed things, we use the ODBC to load the relevant tables to the local PC that runs Access so that all querying is done locally. One of the reports we run allows the user to list all invoices within a period. They are also allowed to select a customer code and a product set on
5
10880
by: Megan | last post by:
Hi everybody- I'm helping a friend with a music database. She has an old one and is creating a new one. She wants to compare records and fields in the old database with records and fields in the new database. For instance, her old database has a table with Band Info in it. Her new database also has a table with Band Info in it but slightly different. I was wondering if there was an easy way to compare the fields from similar tables in...
3
10664
by: google | last post by:
I have a database with four table. In one of the tables, I use about five lookup fields to get populate their dropdown list. I have read that lookup fields are really bad and may cause problems that are hard to find. The main problem I am having right now is that I have a report that is sorted by one of these lookup fields and it only displays the record's ID number. When I add the source table to the query it makes several records...
4
5081
by: jay | last post by:
I am using the dataset object to add a row to a sql server database in vb.net code, as follows: dim drow as DataRow dim cmdBld as new SqlCommandBuilder(mySqlDataAdapter) ds.tables(0).NewRow() drow("field1") = data for field 1 and so forth ds.tables(0).rows.add(drow) cmdBld = New SqlCommandBuilder(mySqlDataAdapter)
3
1877
by: fstenoughsnoopy | last post by:
Ok the complete story. I have a Contact Table, Query and Form, that are used to input and store the contact info for customers. They have FirstName, LastName and Address as the primary key fields to keep out duplicates. I am trying to put a full name box on the query, that uses the FirstName, LastName and Middle Initial and puts them together to form a full name. That I have so far. On my order database(consisting of a master table with...
2
2586
by: SueA | last post by:
Can anyone help me with the code to retrieve the name of the table that a control on a form (that's built off a query) refers to? For instance: qryMfrsAndBrands is based on the tables: tblBrands and tblMfrs formMfrsBrands is based on qryMfrsAndBrands fieldBrandName is on the form and comes from tblBrands via qryMfrsAndBrands.
13
3436
by: kev | last post by:
Hi all, I have created a database for equipments. I have a form to register the equipment meaning filling in all the particulars (ID, serial, type, location etc). I have two buttons at the end of the form which is submit and cancel. After i have clicked submit, the information is stored directly into my corresponding database table. My problem here is i need to retrieve back the information submitted to display all the data that the...
1
4103
maxamis4
by: maxamis4 | last post by:
Hello folks, Here is the backgroup. I am creating an agent that can find a user in LDAP and return the last logon date. Now i am not sure if with active directory you can user the SAMAccountName to retrieve the last computer the users logged on to. But i am looking for a place where i can learn this information. I was hoping someone out there could point me in the right direction. Below is my code which i have been working on. It can...
4
7558
by: Evanescent | last post by:
Hi Guys, I am trying to create a form which allows the users to retrieve records based on the values entered or chosen in the various combo boxes and textboxes, such as the customer's name, invoice number, service number and installation site. The users do not have to enter all the information for the search. Currently, for the Customer's Name Combo Box, the values are retrieved from the Information Table and when a user selects a name, the...
0
9579
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9414
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10197
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10032
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9977
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9848
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8860
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5293
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2810
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.