SQLTeam.com | Weblogs | Forums

Writing a string SQL


#1

I like to put first column data from a City table into Customer table.
I like to write a SQL to resolve this, can please help?

select * from citytable;
example
Paris
London

The string sql should be similar to this SQL
// customer table
SELECT * FROM Customers
WHERE City IN ('Paris','London');


#2

First you need to find out "the join" between the two tables (how do you know which cities a customer lives in).

Lets say you have a field in customers table named cityid that points to field id in citytable, you can do this without changing customers table:

select cust.* /* here you should write each and every field you want as a result */
  from customers as cust
       inner join citytable as city
               on city.id=cust.cityid
 where city.city in ('Paris','London')
;

#3

Thanks

I like to do a query in a same table.
where column 5 has column 1 value?
is this possible?


#4

Show us the table descriptions of both tables (as create statements), some sample data (as insert statement) and your expected result.