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

Asked

Viewed 135 times

1

Each column is composed of names, Fulano, Ciclano, Beltrano etc. I want to select all names that are different. If there is a Joaquin in two columns, you must return one to me. But the problem is not there, it is in the name of the columns that contains point 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 funf neither without [ ] nor with [ ].

Nevertheless , the reason for the question is to know if there is any specification against or any way to run with dot in the names of the columns

   $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)))

  • 2

    Would not be \Col.A`, `Col.B`, `Col.C`, ao invés de entre [ ]`?

  • have tried nickname? type [col.A] as colunaA, [col.B] as colunab..?

  • Inkeliz that’s right, it worked!! The thing is to put in inverted quotes (the crase of our keyboard).

2 answers

0

Have you tried taking the clasps off?

SELECT DISTINCT 
    col.A
FROM stabela 

UNION 
SELECT DISTINCT 
    col.B
FROM stabela 

UNION 

SELECT DISTINCT 
    col.C
FROM stabela
  • That was the first attempt!

  • You need to know which result came from each column?

  • could try: SELECT DISTINCT col, 'A' the columns FROM stabela UNION SELECT DISTINCT col, 'B' the columns STABELA UNION SELECT DISTINCT col, 'C' the columns from STABELA;

  • I understand. I believe the problem is the column name using "." Try to replace the dot with _ See this article I think will help you http://www.devmedia.com.br/standardizca-de-nomenclatura-revised-sql-magazine-100/24710

0


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

Put the column names in the query between inverted single quotes.

$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 crase accent of your keyboard. Shift + accent key and space key. I ran the test on DB and rotated round :)

  • It has everything explained here on documentation, if you would like to add to the reply.

  • 2

    The community being in Portuguese does not exclude the possibility of you using references in English. Especially when it is the official documentation of the tool you are using. As for the point, you will see, if read: Permitted characters in quoted Identifiers include the full Unicode Basic Multilingual Plane (BMP), except U+0000. Quoted dentifiers are identifiers between players, as used in your reply.

  • As I understand it, it references quotation marks for identifiers that are mysql> SELECT * FROM reserved words select WHERE select.id > 100; which is not the case for column names with a dot. Column names with a dot are not reserved words or function names.

  • 1

    If an Identifier contains special characters or is a reserved word, you must quote it Whenever you refer to it., I just tipped you to base your response on a reliable reference. This would greatly increase its reliability. You put the reference if you want,

  • I saw several sites talking about special characters, but none of them referred to the point.

  • Then just read the previous topic "Permitted characters in unquoted Identifiers" and you will see that it is only allowed [0-9,a-z,A-Z$_], not including the point.

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.