Search
 
SCRIPT & CODE EXAMPLE
 

SQL

how to select multiple columns from different tables in mysql

-- MySQL 
-- t1 = table1
-- dt2 = column of table
SELECT t1.dt2, t2.dt4, t2.dt5, t2.dt3 #get dt3 data from table2
FROM table1 t1, table2 t2 -- Doesn't need to have t1, or t2
WHERE t1.dt2 = 'asd' AND t2.dt4 = 'qax' AND t2.dt5 = 456
Comment

mysql view from multiple tables

CREATE VIEW V AS (

  SELECT i.country,i.year,p.pop,f.food,i.income FROM
    INCOME i
  LEFT JOIN 
    POP p 
  ON
    i.country=p.country
  LEFT JOIN
    Food f
  ON 
    i.country=f.country
  WHERE 
    i.year=p.year
  AND
    i.year=f.year
);
Comment

mysql search multiple tables

SELECT
  users_first_name,
  users_last_name
FROM
  (
    (
      SELECT
        users.first_name AS users_first_name,
        users.last_name AS users_last_name
      FROM
        users
        INNER JOIN companies ON companies.id = users.company_id
      WHERE
        (
          users.last_name LIKE 'TERM%'
        )
    )
    UNION
      DISTINCT (
        SELECT
          users.first_name AS users_first_name,
          users.last_name AS users_last_name
        FROM
          users
          INNER JOIN companies ON companies.id = users.company_id
        WHERE
          (users.first_name LIKE 'TERM%')
      )
    UNION
      DISTINCT (
        SELECT
          users.first_name AS users_first_name,
          users.last_name AS users_last_name
        FROM
          users
          INNER JOIN companies ON companies.id = users.company_id
        WHERE
          (companies.name LIKE 'TERM%')
      )
  ) AS union1;
Comment

select multiple tables mysql

SELECT t1.dt2, t2.dt4, t2.dt5, t2.dt3 #get dt3 data from table2
FROM table1 t1, table2 t2 -- Doesn't need to have t1, or t2
WHERE t1.dt2 = 'asd' AND t2.dt4 = 'qax' AND t2.dt5 = 456
Comment

PREVIOUS NEXT
Code Example
Sql :: uuid sqlalcomany 
Sql :: create table kusto 
Sql :: java sql connection close 
Sql :: mssql default connection string 
Sql :: Inserting data into different tables at once in oracle sql 
Sql :: cql insert 
Sql :: Syntax error or access violation: 1075 Incorrect table def inition; there can be only one auto column and it must be defined as a key 
Sql :: sqlite higher or equal 
Sql :: sql check constraint 
Sql :: make selected text uppercase mssql 
Sql :: 0 
Sql :: linux upload database to mysql 
Sql :: mysql group rows with same value 
Sql :: not equal in mysql query 
Sql :: view column type sql server 
Sql :: mysql loop through databases and execute query 
Sql :: how to increase the width of the screen in oracle 
Sql :: sql date between one week 
Sql :: drop unique 
Sql :: foreign key sql 
Sql :: show create table in postgresql 
Sql :: data types in sql 
Sql :: drop specific row postgresql 
Sql :: sql in operator 
Sql :: joining tables in sql 
Sql :: google sheets data validation custom formula filter 
Sql :: inner join vs outer join 
Sql :: cardinality example sql 
Sql :: subquery sql 
Sql :: apex run 404 
ADD CONTENT
Topic
Content
Source link
Name
9+8 =