sql - Linking integer id with text in Postgres -


i can connect database in postgres.

it has table called country 201 rows. consists of 2 fields: country_id (integer) , country_name (text).

it has table called school 2233 rows. consists of field called country (integer). field lists integers each represent 1 of 201 country_id country table.

if command like:

select country school limit 10; 

i can first 10 country_id's. possible me translate these 10 country_id's country_name's using country table?

you can use join achieve this..

i wrote query mysql

create table country (id numeric,  c_name varchar(20));   insert country values(1,'america');  insert country values(2,'india');  insert country values(3,'britain');  insert country values(4,'greece');  insert country values(5,'china');   create table school (school_name varchar(20),  country_id numeric);   insert school values ('a',2);  insert school values ('b',4);  insert school values ('c',5);  insert school values ('d',4);     select c_name  country c join school s on c.id = s.country_id order c_name limit 2  c_name china greece 

if want show country name once can use distinct

also if limit should orderby else give different result on each time..


Comments