Wonder if anybody knows the answer to this...
Say I have two tables "customers" & "orders"
both tables have an "id" field to uniquely identify them. Orders has a field called "customer_id" to link up to the customers table.
I currently run a query like:
SELECT customers.*, orders.* WHERE customers.id=orders.customer_id;
which gives me a nice result table.
However, because both tables contain the field "id" - I get one or the other.
How do I get around this? I remember there being an AS clause, but that would mean adding each field from the table to the select individually.
Can you get it to name the parts of the result set? (i.e so access is like "customers.id" "orders.id")
I could do multiple queries, but I'm sure you must be able to do what I want with a single query.
This is a php website running with a mysql db that i'm working on.
Thanks.
Say I have two tables "customers" & "orders"
both tables have an "id" field to uniquely identify them. Orders has a field called "customer_id" to link up to the customers table.
I currently run a query like:
SELECT customers.*, orders.* WHERE customers.id=orders.customer_id;
which gives me a nice result table.
However, because both tables contain the field "id" - I get one or the other.
How do I get around this? I remember there being an AS clause, but that would mean adding each field from the table to the select individually.
Can you get it to name the parts of the result set? (i.e so access is like "customers.id" "orders.id")
I could do multiple queries, but I'm sure you must be able to do what I want with a single query.
This is a php website running with a mysql db that i'm working on.
Thanks.