简体   繁体   中英

MySQL query from 2 tables, get value of ID?

I have been trying to search without success what I need for my problem, so let me explain it.

I have 2 tables, let's say client and state

On the client table I have this columns:

idClient, name, idState

On the state table I have this columns:

idState, name

What I'm trying to do is a query on MySQL, to get the client info, but at the same time, on the result get the name of the state of the client and not the ID of it.

How can I do this?

Thanks and sorry if its all rdy answer on some place else (could not find the answer for this)

I think you can do with an inner join

 select client.idClient, client.name,  state.name
 from client 
 inner join state on client.idState = state.idState

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM