I am trying to show a table where I am would like to pull the user's name as well as category names. In the database both fields are called name. How do I pull that into my table? Do I need to run two queries? Do I need to somehow alias one of the fields?

Comments

cog.rusty’s picture

Prefix them with their table name:

SELECT user.name, category.name FROM user, category WHERE ......

If you want you can alias them as well for convenience:

SELECT user.name u_name, category.name c_name FROM user, category WHERE ......

nedjo’s picture

something like

SELECT a.name AS a_name, b.name AS b_name FROM table_a a, table_b b

nancydru’s picture

SELECT u.name AS user-name, c.name AS cat-name FROM {users} u INNER JOIN {category} c ON c.uid=u.uid WHERE ...
...
$x = $data['user-name'];
$y = $data['cat-name'];

Nancy W.
Drupal Cookbook (for New Drupallers)
Adding Hidden Design or How To notes in your database

bfbryan’s picture

thanks