Here is query that gets data from category table and display using following code:
there find com_thirdparty and replace with com_your-component-name
$db = JFactory::getDBO();
$query = "SELECT c.id, c.asset_id, c.access, c.alias, c.checked_out, c.checked_out_time,
c.created_time, c.created_user_id, c.description, c.extension, c.hits, c.language, c.level,
c.lft, c.metadata, c.metadesc, c.metakey, c.modified_time, c.note, c.params, c.parent_id,
c.path, c.published, c.rgt, c.title, c.modified_user_id, c.version, CASE WHEN CHAR_LENGTH(c.alias) != 0 THEN CONCAT_WS(':', c.id, c.alias) ELSE c.id END as slug
FROM #__categories as c
LEFT JOIN (SELECT cat.id as id FROM #__categories AS cat JOIN #__categories AS parent ON cat.lft BETWEEN parent.lft AND parent.rgt WHERE parent.extension = 'com_thirdparty' AND parent.published != 1 GROUP BY cat.id) AS badcats ON badcats.id = c.id
WHERE (c.extension='com_thirdparty' OR c.extension='system') AND c.access IN (1,1,5) AND c.published = 1 AND badcats.id is null
GROUP BY c.id, c.asset_id, c.access, c.alias, c.checked_out, c.checked_out_time,
c.created_time, c.created_user_id, c.description, c.extension, c.hits, c.language, c.level,
c.lft, c.metadata, c.metadesc, c.metakey, c.modified_time, c.note, c.params, c.parent_id,
c.path, c.published, c.rgt, c.title, c.modified_user_id, c.version
ORDER BY c.lft";
$db->setQuery($query);
$catresult = $db->loadObjectList();
<!-- display category -->
<select name="category">
<option value="">Select Category</option>
<optgroup>
<?php
foreach($catresult as $categoryoption){
if($categoryoption->level==1){ ?></optgroup><optgroup label="<?php echo $categoryoption->title?>"><?php }
if($categoryoption->level==2){ ?><option value="<?php echo $categoryoption->id?>">- <?php echo $categoryoption->title?></option><?php }
}
?>
</optgroup>
</select>