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

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...

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?

  • 2
  • 2
1 Solution
erzoolanderAuthor Commented:
'item/'.t1.ID I mean.  Forgot the slash
should just be t1.id. You don't need 'item' since you already aliased it with t1
erzoolanderAuthor Commented:
Will it match up though, since URLID = item/5 and t1.id = 5?

Ah missed that part.  So it should be t1.id/5.

It might cause a slow query though as it might not use an index in t1.id (if any).  Well, if it's just a one-time thing then that's okay.  If you plan to do this regularly, suggest you add another column to items with the values already divided by 5.
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: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

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