GraphQL Query to Get Data Two Different Tables

GraphQL Query to Get Data Two Different Tables


0

I have two tables a and b. a have id and age fields. b have id, pid, and name fields. b.pid has a foreign key relationship with a.id. How can I get age and name from these tables using a GraphQL query? Tables are created using SQL.

2

  • Note that table have columns not fields. And never store age, (most) people become older every year. Instead store date of birth.

    – jarlh

    4 hours ago

  • A minimal reproducible example is a great start when asking for SQL assistance.

    – jarlh

    4 hours ago

1 Answer
1


0

This seems to be an SQL question rather than a GraphQL question. If you need to get the name and age, your GraphQL query should look something like this:

query MyQuery {
    profile {
        name
        age
    }
}

But the real issue is how you design and implement your GraphQL API so this query works as expected. In that case, you may use a JOIN statement to retrieve the data within your profile resolver.

SELECT a.age, b.name
FROM a INNER JOIN b
ON a.id = b.pid



Leave a Reply

Your email address will not be published. Required fields are marked *