Hi, In my database I have created table type and content. In type table I have maintained list of parent category and child category , below which I have have to add content.In content table I have list of content added below each category. Fields in type table -id,name,parentid Fields in content table-id,tid ,title I want to join two tables and I have to check for the presence of child category if present or content. I have tried with the following query mysql> select name,title from type left join content on (type.id=content.tid) wh ere parentid=$id; -------+-----------------+ name | title | -------+-----------------+ book | Mailer | book | calender Script | book | Data | book2 | NULL | -------+-----------------+ Problem is I have got the parent category name instead of child category name. Plz help me solve this issue
i didnt understood exactly wht u want.....but i think ur query is not so difficlut. Can u Just put the Two tables' fields and the result you require?
Table:Type Fields id name parentid 1 HTML 0 2 PHP 0 3 HTML script 1 4 PHP script 1 5 Free script 4 Table: Content Fields cntid title tid desc 1 Mailer script 5 Script to send mail 2 Rating script 5 Script to rate I want to select the child of selected parent or select title from content if there is no child and content is present select name,title from type left join content on (type.id=content.tid) wh ere type.parentid=$id; I want to display the child name when the child is present for the passed id. otherwise I want to display title of content if child is not present for id passed. Above query works fine to select child name(if present) but the title is not selected in the absence of child and presence of content.
there is no connection of parentID with contentID and u want to slect title from content from ultimately parentID. U need to define a new relationship i think between content and parent. How can u select title if there is no content/contid agaisnt the tid ? Am I getting right or not? i tried these on ur given data SELECT Content.Title, Type.Name FROM Type LEFT JOIN Content ON Type.tID=Content.cntID WHERE Type.parentID=1; it returned two results with two names for parentID=1 and no title(because there was no title defined for tid=1)
(i may be wrong as i havnt understood completely what u are upto) if u use the same query and also add some content data as 2, ABC script, 1, Script to ratexyz than the query will obviously return the title as well. What I am saying is for the given parentID, if u dont have the Content for the given Type, there would be no title value returned.