I have a table "events" that has the following fields: id
, id_client
, data_field
.
The id_client makes a reference to a table "clients" that has the following fields: id
, name
.
I would like to display in my dataviewgrid the da开发者_Python百科ta_field and the name of my id_client (from the "clients" table).
How can I make a sql statement so that I may fill my dataview with the apropriate data?
(Note that my data_field is actually a lot of fields, but I only named data_field for convenience in explaining.)
You mean like this?:
SELECT events.id, clients.name, events.data_field
FROM events
INNER JOIN clients ON events.id_client = clients.id
This will retrieve all events with their id
, the name
of the associated client, and the data_field
.
(Additionally, if for a given events
record there isn't always a corresponding clients
record then you can replace INNER JOIN
with LEFT OUTER JOIN
.)
精彩评论