Looping through a database query

Hi Experts

I have two tables
keywordmodifiers
uk_england = cities and towns

I want to write a query that takes a keywords and adds then to the county of the uk_england table.

The result should end up being [keyword modifier county]
I want this to loop all the way through the uk_england table and add each keywordmodifier keyword till completion.
The table structures are below

How do you write a looping staement in mysql to do this?

Thanks
keywordmodifiers
 
SELECT
keywordmodifiers.keyword,
keywordmodifiers.pg_id
FROM
keywordmodifiers
 
uk_england
 
 
SELECT
uk_england.id_eng,
uk_england.county,
uk_england.town,
uk_england.postcode,
uk_england.Country
FROM
uk_england

Open in new window

matthewdacruzAsked:
Who is Participating?
 
Steve BinkCommented:
Try this example:

CREATE TABLE `table1` (
  `t1` INTEGER(11) NOT NULL AUTO_INCREMENT,
  `t2` VARCHAR(20) NOT NULL DEFAULT '',
  PRIMARY KEY (`t1`)
) ENGINE=MyISAM;
 
INSERT INTO `table1` (`t2`) VALUES 
  ('Miami'),
  ('New York'),
  ('Chicago'),
  ('Washington'),
  ('Kalamazoo'),
  ('Phoenix'),
  ('Augusta'),
  ('Dallas'),
  ('Boulder'),
  ('Boise'),
  ('Minneapolis'),
  ('Ozarks');
 
CREATE TABLE `table2` (
  `t3` INTEGER(11) NOT NULL AUTO_INCREMENT,
  `t4` VARCHAR(20) DEFAULT NULL,
  PRIMARY KEY (`t3`)
) ENGINE=MyISAM;
 
INSERT INTO `table2` (`t4`) VALUES 
  ('red'),
  ('orange'),
  ('yellow'),
  ('green'),
  ('blue'),
  ('purple'),
  ('brown'),
  ('black');
 
select * from table1 inner join table2;

Open in new window

0
 
Steve BinkCommented:
Your explanation is not clear to me.  Can you provide a specific example of what you would like to happen?
0
 
matthewdacruzAuthor Commented:
HI routinet

I have a table with keywords. For the example say 10 keywords.
I have another table with cities in it. For the example say it have 100 cities.

I want to take write a query that will add the 100 cities to each of the 10 keywords.

for example: keywords = porche
                     city           =  new york

I would like the result to join the two into a phrase "porche new york", "porche miami", "porche california" and so forth till all cities are added. Then it loops and starts with the next keyword.

I hope this is clearer

Thanks

Matt
0
 
matthewdacruzAuthor Commented:
I great I see how you do it. Thanks
0
 
matthewdacruzAuthor Commented:
Thanks for the help
0
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.

All Courses

From novice to tech pro — start learning today.