Hi have the following tables:
table districts:
id DD text
---|----|-----
1 | 01 | texas
2 | 02 | ny
5 | 03 | washington
table councils:
id DD CC text
---|----|----|-----
1 | 01 | 01 | text1
2 | 02 | 01 | text2
5 | 02 | 02 | text3
3 | 02 | 03 | text4
4 | 03 | 01 | text5
5 | 03 | 02 | text6
6 | 01 | 02 | text7
table person:
id name DD CC
---|-------|----|----
1 | john | 02 | 03
2 | mike | 03 | 02
3 | julia | 01 | 02
I want to make a query so I get the following result:
result:
name District Council
-------|------------|-------
john | ny | text4
mike | washington | text6
julia | texas | text7
So far I have the following query:
select p.name,d.text as district,c.text as council
from person p
inner join districts d on p.DD=d.DD
inner join councils c on p.DD=c.DD and p.CC=c.CC
where 1;
I think that the logic should be correct but somehow I’m getting an error… Can anyone help understand this or point me in the right direction??
If I do this it returns results but not the expected of course:
select p.name,d.text as district,c.text as council
from person p
inner join districts d on p.DD=d.DD
inner join councils c on p.CC=c.id
where 1;
Thanks
EDIT: It was a collation problem… My advice if you find this is to not use query browser ’cause errors are not very verbose… There might be an option in it but I dont’t know!
Thank you all
I had no idea of your schema, but here’s what I did (and it works fine!)