Jump to content

Help Is CONCAT what I need?


Popgun

Recommended Posts

Hi All

 

Im trying to construct a recordset that combines the State col from a users table with the state col from a location table, as an alias so that I can dynamically pull the users Zip code and City from the location table for location_ID (assignment) and update in a form. I cant seem to get the CONCAT part of the SQL to work:

 

This works:

 

SELECT *

FROM USERS, LOCATION

WHERE user_ID = colname  AND USERS.`state` = LOCATION.stateabbreviation 

 

This does not:

 

SELECT *

FROM USERS, LOCATION

WHERE user_ID = colname  AND USERS.`state` = LOCATION.stateabbreviation 

CONCAT(USERS.`state`, LOCATION.stateabbreviation) AS state

 

Neither does this:

 

SELECT *

FROM USERS, LOCATION

WHERE user_ID = colname  AND USERS.`state` = LOCATION.stateabbreviation 

SELECT CONCAT('state', 'stateabbreviation') AS state

 

Getting a syntax error near CONCAT

 

Any help is greatly appriciated, new to MySQL

Link to comment
Share on other sites

fenway,

 

Thanks man I had the order wrong I guess you learn something new everyday right? (hopefully!!)

 

Now I have to figure out how to limit the results based on the alias state to pull the zip code and cities associated with that state for population in the form O.o

Link to comment
Share on other sites

I guess the simpilest explaination is I'm trying to assign a location ID from the location table to a user_ID from the user table.

 

I need to be able to identify the users location so I can match them to a nearby service provider.

 

The table structure is such:

LOCATION

 

location_ID

zip

city

stateabbreviation

latitude

longitude

 

USERS

 

user_ID

location_ID

state (1 of 15 specific states, also abbreviated, as I only have service providers in 15 states at the moment)

 

 

So I'm using CONCAT to form an alias on state, so I can pull ONLY the ZIP codes and Cities from those 15 states rather than the entire LOCATION table

 

I'm not sure if there is a better way to do this, I made some headway last night using applying DISTINCT and a LEFT JOIN, but it needs to be refined a bit.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.