You need to sign in to do that
Don't have an account?

is this correct query... its showing error like--------> unexpected token: '['
accountname = [select id,name,[select id, firstname from contact] from account];
You need to sign in to do that
Don't have an account?
accountname = [select id,name,[select id, firstname from contact] from account];
list<account> accountname = [select id,name,(select id, firstname from contact) from account];
Slight update - you need to use the plural to get the related contacts:-
list<account> accountname = [select id,name,(select id, firstname from contacts) from account];