vendredi 5 mai 2017

How to find two different matched data for one parent id?

Hi i have to search iron and van. In my search condition iron is in one row and van is in another row. Both are have the same parent id. How did i find the both records in one mysql query.

i'm using this query.

SELECT * FROM  `products prod,parents p ` 
WHERE  `p.id` =1 AND prod.name = 'Van' AND prod.name = 'Iron'

This is my table

Parent

     id    
----------
     1    
     2    

Child

     id   |   name   |   parent   
---------------------------------
     5    |   iron    |     1
     6    |   van     |     1
     7    |   jane    |     2

i want

id | name | parent
------------------
5  | van  | 1
6  | iron | 1

How can i get the output like i mentioned.

Aucun commentaire:

Enregistrer un commentaire