Find/Replace query


These are the dreaded words; I'm a newbie to SQL.

I'm developing a business directory, and I need to import data from my existing database into the new one.

I need to import some data from one table to another in MYSQL before exporting it as CSV, and importing it to the new database.

In one table, the categories table, there are two fields, "ID" and "Category Name".

In the "listings" table, there are all the usual fields (username, password etc) and then "Type", which corresponds to the category ID.

What I would like to be able to do is something like this;

1) Search the field "type" in the listings table
2) Get the number from that field
3) If the number from that field matches the number in "id", in the categories table, Populate the "type" field with the corresponding text from "Category Name"
4) Save.

Is this possible to do in a SQL query, or with PHP? I'd love to find out, I hope someone out there can help me!



Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


In this Discussion