Hello. Such a question on Delphi: there are three tables, on the form TTable, DataSourse, DBGrid. In each of the tables, there is a column "inv_N", and how to make a search, simultaneously in three tables on this column?
- oneDescribe the structure of the base. And what you need to find. Grid move to this inventory number or how? What will happen if such a number is only in one table, or if there are several such numbers? Are you searching hard or by entry? Need more details. - Yura Ivanov
|
2 answers
See JOIN methods: Explaining SQL JOIN / INNER / OUTER unions .
|
First, change TTable to TQuery or TDataSet
Then write a SQL query of something like
select inv_N from table1 union select inv_N from table2 union select inv_N from table3
And there already or you can use filter or locate
Though it is more correct to make where in request.
- It does not work for a variety of tables !!! - AseN
- This is like a set and it will work JOIN depletes the tables putting the fields side by side, and the union returns the values of one-field fields of different tables under each other as one table. - Vahan Av
- if for each of the tables there is a grid, then such a union will not work. There is some obvious non-optimality with the base. - Yura Ivanov
- Well, if for each its own grid, then it will be necessary to look 3 times)). if inv_N primary key problems should arise. And if not, then you need to think about optimizing the base. - Vahan Av
|