Jump to content

[SOLVED] Quick query question


Brian W

Recommended Posts

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

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

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

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

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.