Abdullah A AlMayouf
Abdullah A AlMayouf

Reputation: 11

Join one to many

I have two tables,

The first table has a Primary Key called PKID table A:

PKID     | name
------ | ------
1      | A
2      | b

The second table has the PKID column from table A as a foreign key table B:

PKID     | name
------ | ------
1      | true
1      | false
2      | false
2      | false
2      | false

I need select all rows from table A when all child's have ( false ) value from table B

I would like output the following table :

id     | name
------ | ------
2      | b

Upvotes: 1

Views: 40

Answers (2)

Riajul Islam
Riajul Islam

Reputation: 1483

Please try this:

SELECT * from A LEFT JOIN B on B.PKID=B.PKID where B.name ='false' 

Upvotes: 1

Deepankar Chopra
Deepankar Chopra

Reputation: 50

You can use the following query for this, GROUP_CONCAT function will be useful in this case

SELECT GROUP_CONCAT(DISTINCT B.name) as allData,B.PKID FROM A INNER JOIN B ON A.PKID = B.PKID GROUP BY B.PKID HAVING allData="false"

Upvotes: 1

Related Questions