How do you conquer the values of 3 pillars into 1?



  • Hey, everybody. I have two tables:

    Avto:

    ID ID_driver
    1  23
    2  32
    

    Driver

    ID_driver  Name   Surname
    23         Misha   Volkov
    32         Valera  Petrov
    

    As I am requested to remove the name and the name of the driver in one field in order to obtain the following from Table Avto

    ID Name_Driver
    1  Misha Volkov
    2  Valera Petrov
    

    Now I have a request, but, uh, he's taking out different fields.

    SELECT A.*, DR.NAME AS NAME, DR.SURNAME AS SURNAME
    FROM Avto A
    INNER JOIN DRIVER DR ON A.ID_Driver = DR.ID
    

    That's what happens.

    ID ID_driver  Name   Surname
    1    23       Misha  Volkov
    2    32       Valera Petrov
    


  • response for interbase/firebird: select char_field1 || ' ' || char_field2 (singing on the floor with the right name )

    Initially mysql/sql, so the answer about mysql will be left for history:

    google://mysql concatand, in principle, when you want something to connect/start lines (in any language, even mysql, at least python), googlet. concat+mysqlconcat pythonAnd then ask the question here, it'll be a good tone.

    As an exercise, you may correct this decision:

    SELECT A.*, CONCAT(DR.NAME, '%', DR.SURNAME) as driverName
    FROM Avto A
    INNER JOIN DRIVER DR ON A.ID_Driver = DR.ID
    

    And please, if you don't think about yourself, think about the others, don't write the names of the tables and fields of CAPSOM. SQL should be written by SQL operators. Otherwise, when you're going to deflect your enquiries without syntaxis lighting, too, will curse you with a black word.

    P.S., please clarify the database, because you removed the gate mysql.

    mysql> use db;
    Database changed
    mysql> 
    mysql> create table driver (name text, surname text);
    Query OK, 0 rows affected (0.22 sec)
    

    mysql> insert into driver values ('vanya', 'petrov');
    Query OK, 1 row affected (0.03 sec)

    mysql> select concat(name, surname) from driver;
    +-----------------------+
    | concat(name, surname) |
    +-----------------------+
    | vanyapetrov |
    +-----------------------+
    1 row in set (0.00 sec)

    mysql> select concat(name, surname) as kek from driver;
    +-------------+
    | kek |
    +-------------+
    | vanyapetrov |
    +-------------+

    The author can only be forgiven because he has no knowledge of the existence of a bunch of SQL dialects.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2