INER JOIN first time writing

Post here if you need help with SQL.
Post Reply
hostingebc
Posts: 28
Joined: Wed Jun 08, 2011 10:31 am

INER JOIN first time writing

Post by hostingebc »

I write first time INER JOIN and i have error

Unknown column 'posts.id' in 'field list'


this is the query
[syntax=php]<?php
$query = "SELECT posts.id AS post_id, categories.id AS category_id,
title, contents, date_posted, categories.name
FROM posts
INER JOIN categories ON categories.id = posts.cat_id";
mysql_query($query)or die(mysql_error());

?>[/syntax]
and,
in my DB structure i have 2 tables:
1. categories - id, name,
2. postos - id, cat_id, title, contents, date_posted

wer is the problem?

thanks
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: INER JOIN first time writing

Post by jacek »

are you sure the posts table has the column id, and not ID or something else.
Image
hostingebc
Posts: 28
Joined: Wed Jun 08, 2011 10:31 am

Re: INER JOIN first time writing

Post by hostingebc »

Copy/paste header from php my admin
posts:
id cat_id title contents date_posted

categories:
id name
hostingebc
Posts: 28
Joined: Wed Jun 08, 2011 10:31 am

Re: INER JOIN first time writing

Post by hostingebc »

hostingebc wrote:in my DB structure i have 2 tables:
1. categories - id, name,
2. postos - id, cat_id, title, contents, date_posted

wer is the problem?

thanks


UPDATE for secon table name

2. posts: id, cat_id, title, contents, date_posted
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: INER JOIN first time writing

Post by jacek »

hmm it does seem that you have a column called that.

you could try quoting the table and column names with backticks `
Image
Tino
Posts: 360
Joined: Thu May 05, 2011 8:55 pm
Location: The Netherlands

Re: INER JOIN first time writing

Post by Tino »

Your table is postos, but you specify you're selecting from the posts table.

That's your problem ;)
Please check out my CodeCanyon items.
Post Reply