Brian W Posted January 27, 2009 Share Posted January 27, 2009 I've been writing my queries like this: SELECT m.URL as URL, c.Name as Name FROM media m LEFT JOIN contacts c ON m.contact_id = c.ID I use aliases so that I can use em like $result['Name']. Can I say something like SELECT m.*, c.* FROM media m LEFT JOIN contacts c ON m.contact_id = c.ID and still use the results, or do I need to specify each field individually. Any input is appreciated. Thanks Link to comment https://forums.phpfreaks.com/topic/142645-solved-quick-query-question/ Share on other sites More sharing options...
rhodesa Posted January 27, 2009 Share Posted January 27, 2009 i assume this is MySQL...if so, it should be in the MySQL forum...and yes. just be careful of overlap on variable names. so if both tables have the column Name, you may get unexpected results. you can also do this: SELECT * FROM media m LEFT JOIN contacts c ON m.contact_id = c.ID Link to comment https://forums.phpfreaks.com/topic/142645-solved-quick-query-question/#findComment-747650 Share on other sites More sharing options...
Brian W Posted January 27, 2009 Author Share Posted January 27, 2009 it is mysql, and I did think to put it on that board... but my question more relates to using PHP to handle the results of the query. In regards to your answer, thank you much. I'll pick brains a bit more with this... any way to do something like $result['m.URL'] (which I know doesn't work). That way if my tables have overlapping fields, I don't get hell to pay. Thanks again, Rhodesa Link to comment https://forums.phpfreaks.com/topic/142645-solved-quick-query-question/#findComment-747657 Share on other sites More sharing options...
rhodesa Posted January 27, 2009 Share Posted January 27, 2009 it is mysql, and I did think to put it on that board... but my question more relates to using PHP to handle the results of the query. In regards to your answer, thank you much. I'll pick brains a bit more with this... any way to do something like $result['m.URL'] (which I know doesn't work). That way if my tables have overlapping fields, I don't get hell to pay. Thanks again, Rhodesa my rule of thumb is to never have overlapping field names...for instance, in my tables my column names would be media_name and contact_name. if there is overlap, you need to alias them individually Link to comment https://forums.phpfreaks.com/topic/142645-solved-quick-query-question/#findComment-747663 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.