I
I
Ivan Balan2014-01-09 06:57:51
PostgreSQL
Ivan Balan, 2014-01-09 06:57:51

How to display the value of the associated field in the database?

There are 2 tables:
-Cars
-Marks
"Cars"
table fields -id_car
-MarkID
-CarNumber
-Fuel
-isActive
"Brands" table fields
-id_mark
-MarkName MarkID and idMark fields are connected. There is a grid in which the "Cars" table is displayed , but it is necessary that instead of numbers in the MarkID field, the value of the "MarkName" field be indicated, that is, that the value of the "Marks" table would be decoded by the corresponding ID, and instead of the numbers of the ID number, the name of the brand would be shown.

I did it programmatically in the OnGetData method, but if there is too much data, it starts to slow down significantly. I am not a guru in this matter, so I ask you for help, thank you.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Rsa97, 2014-01-09
@Toddams

SELECT `a`.`id_car`, `m`.`MarkName`, `a`.`CarNumber`, `a`.`Fuel`, `a`.`isActive` 
    FROM `Автомобили` AS `a` 
        LEFT JOIN `Марки` AS `m` ON `a`.`MarkID` = `m`.`id_mark`

V
Volodymyr S., 2014-01-09
@VYBGSS

SELECT auto.id_car,
    auto.CarNumber,
    auto.Fuel,
    auto.isActive,
    (SELECT TOP(1) mark.MarkName
    FROM Марки as mark
    WHERE mark.MarkID = auto.id_mark)
FROM Автомобили as auto
ORDER BY auto.id_car

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question