Avatar of erzoolander
erzoolander

asked on 

MySQL Left Join - Appending to variable

I'm joining two tables.  

Let's say table one is...

Table Name: items

Item        ID
Widget    5

Table two:

Table Name: prices

Item Price         URLID
25.00               item/5

My SQL goes like...

SELECT *
FROM items t1
LEFT JOIN prices t2 ON t2.URLID = 'item'.t1.ID
WHERE t1.ID = '5'

What would the proper syntax be to do that?

As you can see - ID's variable in the first table (in this instance 5) relates to the 'item/VARIABLE' in the second table (in this instance, item/5).

The " t2.URLID = 'item'.t1.ID" is apparently wrong syntax - as it doesn't work.

How would I properly phrase that?

Thanks!
MySQL Server

Avatar of undefined
Last Comment
johanntagle
Avatar of erzoolander
erzoolander

ASKER

'item/'.t1.ID I mean.  Forgot the slash
Avatar of johanntagle
johanntagle
Flag of Philippines image

should just be t1.id. You don't need 'item' since you already aliased it with t1
Avatar of erzoolander
erzoolander

ASKER

Will it match up though, since URLID = item/5 and t1.id = 5?

ASKER CERTIFIED SOLUTION
Avatar of johanntagle
johanntagle
Flag of Philippines image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
MySQL Server
MySQL Server

MySQL is an open source, relational database management system that runs as a server providing multi-user access to a number of databases. Acquired by Oracle in 2009, it is frequently used in combination with PHP installations, powering most of the WordPress installations.

49K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo