envexlabs Posted September 9, 2008 Share Posted September 9, 2008 Hey, I have this query: SELECT * FROM `store` LEFT JOIN `directory_link` ON store.id = directory_link.item_id WHERE directory_link.cat_id = 2 Which prints this: Array ( [id] => 16 [contact_name] => Matt Vickers [name] => Connect Four => ------- [password] => kmladhlkashldkfjhasljd [slug] => connect_four [mem_type] => 1 [pic] => 1_09172007-12-1280X1024.jpg [address] => 250 Mc Dermot [phone] => 204.229.3215 [cat_id] => 2 [paid] => 0 [item_id] => 1 [is_store] => 1 ) The problem i'm having is that directory_link.id is overwriting my store.id which is quite important. Is there a way to remove directory_item.id from the final output? Thanks, envex Quote Link to comment Share on other sites More sharing options...
JonnoTheDev Posted September 9, 2008 Share Posted September 9, 2008 Rather than using a * in your SELECT statement (which is everything), only select the fields you want to return. SELECT field1, field2 FROM..... Quote Link to comment Share on other sites More sharing options...
envexlabs Posted September 9, 2008 Author Share Posted September 9, 2008 I was hoping there was a different way than that Thanks! Quote Link to comment Share on other sites More sharing options...
Mchl Posted September 9, 2008 Share Posted September 9, 2008 Your query implies that directory_link.id is equal to store.id Wrong. You can use something like this: SELECT *, store.id AS storeID .... Quote Link to comment Share on other sites More sharing options...
JonnoTheDev Posted September 9, 2008 Share Posted September 9, 2008 I was hoping there was a different way than that Why? Its basic SQL syntax Quote Link to comment Share on other sites More sharing options...
fenway Posted September 10, 2008 Share Posted September 10, 2008 The problem i'm having is that directory_link.id is overwriting my store.id which is quite important. You wouldln't have this problem if you named your PK store_id and directory_link_id -- this also makes it very easy to design FK constraints, JOIN conditions, etc. It's a good convention to adopt. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.