If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > How to build mysql query for this?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-26-10, 06:32
nsatheesh87 nsatheesh87 is offline
Registered User
 
Join Date: Mar 2010
Posts: 5
How to build mysql query for this?

table1:dynamic_info
catgory_id page_id title
6 1 test
table2:category
category_id parent_id category_name
1 0 travel
6 1 car

This is my table structure.

Here What i need is.

output:TRavel car test

In table 2
if parent id is 0 means it is category'
if parentid is 1 means car is the subcategory of catgory travel..
I cant build this one.. please help me
Reply With Quote
  #2 (permalink)  
Old 03-26-10, 06:53
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
Code:
SELECT parent.category_name
     , child.category_name AS subcategory_name
     , dynamic_info.title
  FROM category AS parent
INNER
  JOIN category AS child
    ON child.parent_id = parent.category_id
INNER
  JOIN dynamic_info
    ON dynamic_info.catgory_id = child.category_id
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 03-26-10, 09:41
mike_bike_kite mike_bike_kite is offline
vaguely human
 
Join Date: Jun 2007
Location: London
Posts: 2,519
Rudy - you should get a prize for simply being able to work out the question, it just looked like a random jumble of words to me
__________________
Mike
Reply With Quote
  #4 (permalink)  
Old 03-26-10, 10:02
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
thanks mike
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On