Page 1 of 1
small query problem
Posted: Fri Mar 07, 2008 8:43 am
by itsmani1
my query is :
select * from category where parentid =6
this gives me all children of number 6, I wanted to select name of cat 6 as well.
Please help me out
Re: small query problem
Posted: Fri Mar 07, 2008 8:54 am
by Zoxive
Very difficult to understand what you want. No explanation, my best guess is the categories table is a recursive table within itself, the parent id links to other categories, and you would like to get the name of the parent category.
Code: Select all
SELECT c.*, p.name
FROM `category` c
LEFT JOIN `category` p ON p.id = c.parentid
WHERE `parentid` = 6
Selects everything from Category where parent id is 6, then joins the parent category on the id to get the name.
Re: small query problem
Posted: Fri Mar 07, 2008 10:01 am
by itsmani1
~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:
Posting Code in the Forums to learn how to do it too.
a last small question
i used
Code: Select all
SELECT TIMEDIFF('2000:01:01 00:00:00', '2000:01:02 00:00:00')
it returns me:
-24:00:00
I wanted to show it like
-24 Hours
if my input is
Code: Select all
SELECT TIMEDIFF( '2000:01:01 00:00:00', '2000:01:02 00:30:00' )
i wanted to show it
-24 Hours:30 Mins
~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:
Posting Code in the Forums to learn how to do it too.