0

Let's suppose there is a set of A and for each a of A there is a set of B. In short: A:B = 1:n

Let's suppose, there is an a, which is an A and it is interesting. However, I would like to select a with all its B elements.

For instance, let's consider the example of Companies and Workers. For the sake of simplicity, we assume that a Worker works at a single Company and a Company might have a natural number of Workers.

If I want to select a set, containing the values of Company.Name, Worker.Name of a given Company, then what should I do in PHP, to achieve the expected result?

Charles
  • 50,943
  • 13
  • 104
  • 142
Lajos Arpad
  • 64,414
  • 37
  • 100
  • 175

1 Answers1

1

Based on your example, assuming you have this schema

Table Company

  • CompanyID (PK)
  • CompanyName
  • other columns..

Table Worker

  • WorkerID (PK)
  • WorkerName
  • CompanyID (FK)

You can join the tables by linking Company and Worker with CompanyID

SELECT  a.Name CompanyName,
        b.Name WorkerName
FROM    Company a
        INNER JOIN Worker b
            ON a.CompanyID = b.CompanyID

To further gain more knowledge about joins, kindly visit the link below:

John Woo
  • 258,903
  • 69
  • 498
  • 492
  • Thank you, but the reason I am using an ORM is that I want to avoid writing SQLs. Is there a way in Flourish to achieve a join without writing SQL queries? – Lajos Arpad May 17 '13 at 13:18