Solved

mysql - like statement

Posted on 2012-04-13
5
234 Views
Last Modified: 2012-06-27
Hi,

Trying to list from table courier all couriers whose courier IDs are in table1. However, I am using the like statement because it will not be an exact match up. E.g. in table courier I may have UK00062884, whereas in table1 the entry may just be 62884. Each number is unique though, for instance in this instance, 62884 is definitely courier UK00062884. This code works for just a single hardcoded one

SELECT * from courier where `courier`.`CourierID` LIKE CONCAT('%',"62884",'%');

Open in new window


but neither of these work

SELECT * from courier where `courier`.`CourierID` LIKE CONCAT('%','table1.courier2','%');

Open in new window


or

SELECT * from courier where `courier`.`CourierID` LIKE CONCAT('%',table1.courier2,'%');

Open in new window


somebody help me out?

thanks.
0
Comment
Question by:RupertA
  • 3
  • 2
5 Comments
 
LVL 6

Expert Comment

by:stavros41
ID: 37842782
Try this:
SELECT * from courier where `courier`.`CourierID` LIKE '%62884%';

Open in new window

0
 

Author Comment

by:RupertA
ID: 37842916
stavros,

ahh no, I may not have been clear here. What I need to do is to list all the couriers from table courier that are in table1. u cud use this.

SELECT * from courier where `courier`.`CourierID` IN( select courier2 from table1);

However the problem is that they are not exact, table1 may have 1234, whereas courier may have IR0001234. They are def same person though, hence why I was trying to use "like".

thanks.
0
 
LVL 6

Accepted Solution

by:
stavros41 earned 500 total points
ID: 37843018
Ok, how about this:

SELECT * FROM courier JOIN table1 ON `CourierID` like CONCAT('%',courier2,'%')

Open in new window

0
 

Author Comment

by:RupertA
ID: 37843075
yeaaaaah, that works great :)

Thanks!!
0
 
LVL 6

Expert Comment

by:stavros41
ID: 37843240
No problem, please accept the answer to allocate points.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Trigger usage 2 83
mysql between clause 2 41
PHP insert data in to database... this is not letting me in insert data...please help! 7 71
MySQL recovery 7 27
Introduction In this installment of my SQL tidbits, I will be looking at parsing Extensible Markup Language (XML) directly passed as string parameters to MySQL 5.1.5 or higher. These would be instances where LOAD_FILE (http://dev.mysql.com/doc/refm…
Creating and Managing Databases with phpMyAdmin in cPanel.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question