Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

need to select where table.col like table2.col2

Status
Not open for further replies.

dangari

Programmer
Aug 5, 2009
9
KE
Hi all,

Am having trouble trying to retrieve records using the following SQL statement:

Code:
SELECT DISTINCT(dbS.tCline.mobile),dbS.tCline.msg,dbS.tCline.dest,dbS.tCline.reply,dbS.tCline.statusFROM dbS.tCline,dbLaw.FORMER_GREYWHERE dbS.tCline.msg LIKE '%'||dbLaw.FORMER_GREY.C||'%' ANDdbS.tCline.msg LIKE '%ADMISSION%'SELECT distinct(dbS.tCline.mobile),dbS.tCline.msg,dbS.tCline.dest,
dbS.tCline.reply,dbS.tCline.status
FROM dbS.tCline,dbLaw.FORMER_GREY
where dbS.tCline.msg LIKE '%'||dbLaw.FORMER_GREY.C||'%' and
dbS.tCline.msg like '%ADMISSION%'

My problem now is that, the resultset retrieved includes everything from dbLaw.FORMER_GREY.C instead of only those rows that match dbS.tCline.msg rows.Please assist and be sure that your help is much appreciated.
Thank you in advance
 
would you please try pasting your query again, there are serious syntax errors with what you've posted

also, please confirm which version of mysql you're using

r937.com | rudy.ca
Buy my new book Simply SQL from Amazon
 
Thanks for looking at my post.The syntax I have posted is spot-on except for the area where I need help with where dbS.tCline.msg LIKE '%'||dbLaw.FORMER_GREY.C||'%'
Please note that this is what someone posted as a solution in a certain Oracle blog but didn't work for me in MySQL.

The version of MySQL that am using is 5.1.37. Thanks
 
Sorry it seems I must pasted the code twice..Here it is :
SQL:
SELECT DISTINCT(dbS.tCline.mobile),dbS.tCline.msg,dbS.tCline.dest,dbS.tCline.reply,dbS.tCline.status FROM dbS.tCline,dbLaw.FORMER_GREY WHERE dbS.tCline.msg LIKE '%'||dbLaw.FORMER_GREY.C||'%' AND dbS.tCline.msg LIKE '%ADMISSION%
The syntax above is spot-on except for the area where I need help with where dbS.tCline.msg LIKE '%'||dbLaw.FORMER_GREY.C||'%'
Please note that this is what someone else posted as a solution in a certain Oracle blog but didn't work for me in MySQL.

The version of MySQL that am using is 5.1.37. Thanks
 
Here is the full-proof solution:


SQL:
SELECT distinct(s.mobile),s.msg,r.imei,s.dest,
s.reply,s.status from dbS.tCline s
INNER JOIN dbLaw.FORMER_GREY r ON s.msg LIKE concat('%',concat(r.C,'%')) where s.msg like '%SOLD%'

Many thanks!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top