small query problem

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
itsmani1
Forum Regular
Posts: 791
Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:

small query problem

Post 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
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Re: small query problem

Post 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.
User avatar
itsmani1
Forum Regular
Posts: 791
Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:

Re: small query problem

Post 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: :arrow: 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: :arrow: Posting Code in the Forums to learn how to do it too.
Post Reply