Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

query help

Status
Not open for further replies.

blanius

Programmer
Mar 3, 2002
30
US
I'm a bit rusty at hand coding a query

What I want to do is select all fields form table 'videos' where cat=1

but I want the an additional field that shows the cat name instead of the id from cat. The field cat in the table videos corresponds to the id field in the category table.

Bret Lanius
 
Select cat.videos, categoryname.category FROM videos, category WHERE videos.cat=1 and category.id=videos.cat;

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Thanks, close enough... Fixed it to be
SELECT videos.name, videos.name, category.name
FROM videos, category
WHERE videos.cat =1
AND category.id = videos.cat

and that got me what I needed. I was close before just missed it a bit.

Again thanks.

Bret Lanius
 
I inverted the table name for videos.cat. but I'm glad you got what I meant.

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
why stop with the job half done? you could fix it completely

SELECT videos.name, videos.name, category.name
FROM category
[red]INNER JOIN[/red] videos
[red]ON[/red] videos.cat = category.id
WHERE category.id = 1



r937.com | rudy.ca
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top