Select in multiple columns with dot in name does not return result

1

Each column is composed of names, so-and-so, cyclamen, beltran etc. I want to select all names that are different. If Joaquim exists in two columns, he must return one. But the problem is not there, it's in the name of the columns that contain col.A col.B Col.C I do not know if this is allowed, I have not read anything against but the case is that it does not work with neither [] nor [] .

However, the reason for the question is whether there are any specs against or some way of doing dot com in the column names

   $result = mysql_query("SELECT DISTINCT [col.A] FROM stabela UNION SELECT DISTINCT [col.B] FROM stabela UNION SELECT DISTINCT [col.C] FROM stabela");

    while($row = mysql_fetch_array($result)){
      $nome=$row['col.A'];
    }
  

Warning: mysql_fetch_array (): supplied argument is not a valid MySQL result resource in ....... on line 58

     

Line 58 is (while ($ row = mysql_fetch_array ($ result)))

    
asked by anonymous 23.03.2017 / 23:19

2 answers

0

I will post here the found solution found in the MySQL Certification Study Guide and also in the documentation recommended by our friend Anderson Carlos Woss Schema Object Names

Place the column names in the query in single inverted quotation marks.

$query = mysql_query("SELECT DISTINCT 'col.A' FROM stabela UNION SELECT DISTINCT 'col.B' FROM stabela UNION SELECT DISTINCT 'col.C' FROM stabela");

These inverted quotes are nothing more than the accent of your keyboard. Shift + Accent key and Space key. I did the test in the DB and swirled round:)

    
24.03.2017 / 05:12
0

Have you tried to remove the brackets?

SELECT DISTINCT 
    col.A
FROM stabela 

UNION 
SELECT DISTINCT 
    col.B
FROM stabela 

UNION 

SELECT DISTINCT 
    col.C
FROM stabela
    
24.03.2017 / 02:03