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 Link to comment https://forums.phpfreaks.com/topic/123450-excluding-a-row-from-a-query/ 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..... Link to comment https://forums.phpfreaks.com/topic/123450-excluding-a-row-from-a-query/#findComment-637590 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! Link to comment https://forums.phpfreaks.com/topic/123450-excluding-a-row-from-a-query/#findComment-637591 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 .... Link to comment https://forums.phpfreaks.com/topic/123450-excluding-a-row-from-a-query/#findComment-637593 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 Link to comment https://forums.phpfreaks.com/topic/123450-excluding-a-row-from-a-query/#findComment-637598 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. Link to comment https://forums.phpfreaks.com/topic/123450-excluding-a-row-from-a-query/#findComment-638351 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.