4

I have Two tables named

1.Categortable

Category

Mouse

Computer

Electronics

and the second table Texttable

category                   Text

Mouse                     Logitech Mouse

Computer                  LG Computer

Electronics               LG Electronics

Here I need To select Text for each category in Categortable from Texttable

Can any one help how to loop this to get the output.

2 Answers 2

4

No need to do any looping here, a simple JOIN should work for you:

SELECT * 
FROM CategoryTable CT
    LEFT JOIN TextTable TT ON CT.Category = TT.Category

I've used a LEFT JOIN in case you want to return rows from your Category table which don't have a corresponding match in the Text table.


In case you only want the matching records, just replace the LEFT JOIN with an INNER JOIN.

Sign up to request clarification or add additional context in comments.

Comments

1

try out this

Select ct.category, tt.Text from Categorytable ct
inner join Texttable tt on ct.category = tt.category

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.