Forum Moderators: coopster

Message Too Old, No Replies

mysql query help

something like SELECT x.y FROM me

         

electricocean

11:18 pm on Jun 4, 2005 (gmt 0)

10+ Year Member



What is using the dot in between field on quers such as SELECT x.y FROM me?

Whats it for?

Whats it called?

thanks,
electricocean

Blackie

11:27 pm on Jun 4, 2005 (gmt 0)

10+ Year Member



When you do SELECT from two or more tables that have same column names you will need the dot to tell SQL which table you want this column from.

Example
SELECT table1.column, table2.column FROM table1, table2 WHERE table1.column <> table2.column

Hope this does make sense.

saoi_jp

7:04 am on Jun 5, 2005 (gmt 0)

10+ Year Member



...so if you're only using one table, you won't need it. Say you want all the books that start with "B" listed:

select id, title
from books
where title like 'b%' order by title desc

But if you've got two tables, you'll need it. Say you've got a separate table for author information:

select books.id as id,
books.title as title,
authors.name as author
from books, authors
where books.authorID = authors.id
and books.title like 'b%'
order by books.title desc

(It's an impractical example, since some books have multiple authors.)

coopster

9:01 pm on Jun 5, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Whats it for?

To remove ambiguity.

Whats it called?

a qualifier

Resource:
[dev.mysql.com...]

Blackie

10:48 pm on Jun 6, 2005 (gmt 0)

10+ Year Member



Example of saoi_jp is not that illustrating since the columns have diferent names and you could drop the name of the table without any hassle, but say if you had two columns in two tables with same name (for example id) then you clearly see the need of qualifier.