• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 252
  • Last Modified:

mysql - like statement

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
RupertA
Asked:
RupertA
  • 3
  • 2
1 Solution
 
stavros41Commented:
Try this:
SELECT * from courier where `courier`.`CourierID` LIKE '%62884%';

Open in new window

0
 
RupertAAuthor Commented:
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
 
stavros41Commented:
Ok, how about this:

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

Open in new window

0
 
RupertAAuthor Commented:
yeaaaaah, that works great :)

Thanks!!
0
 
stavros41Commented:
No problem, please accept the answer to allocate points.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now