CREATE VIEW users_info AS
SELECT
    users.user_id as user_id,
    users.Phone as Phone,
    users.pass as pass_val,
    users.regTzintukim as regTzintukim,
    users.import_id as import_id_val,
    users.ts_create as ts_create,
    users_data_count.desks as desks,
    users_data_count.cards as cards,
    IF(Tzintukim.user_id is null, 0, 1) as Tzintukim,
    IF(pass is null, 0, 1) as pass,
    IF(import_id is null, 0, 1) as import_id,
    IF(INSTR(settings, "order_rep") IS NULL, 0, 1) AS order_rep,
    IF(INSTR(settings, "repMenu") IS NULL, 0, 1) AS repMenu,
    IF(INSTR(settings, "repTimening") IS NULL, 0, 1) AS repTimening,
    IF(user_import_from is null, 0, 1) as import_from,
    IF(user_import_to is null, 0, 1) as import_to
FROM
    users
    LEFT JOIN users_data_count on users.user_id = users_data_count.user_id
    LEFT JOIN (
        SELECT
            DISTINCT user_id
        from
            Tzintukim
    ) Tzintukim on users.user_id = Tzintukim.user_id
    LEFT JOIN (
        SELECT
            DISTINCT cards_data_base.user_id as user_import_from
        from
            cards_data_base
        where
            card_import_source
    ) import_from ON users.user_id = import_from.user_import_from
    LEFT JOIN (
        SELECT
            DISTINCT cards_data_base.user_id as user_import_to
        from
            cards
            join cards_data_base on cards.import_source = cards_data_base.card_id
        where
            cards.import_source
    ) import_to ON users.user_id = import_to.user_import_to