Sql two select statements in one query – stack overflow, ems order single query

Sql two select statements in one query – stack overflow, ems order single query - NewsliveSite
SQL: Two select statements in one query – Stack Overflow, ems order single query.

3 years, 8 months ago

I want to select information from two SQL tables within one query, the information is unrelated though, so no potential joints exist.

An example could be the following setup.

I want to have a query that gives me the following:

I tried to follow this logic: Multiple select statements in Single query but the following code did not work:

Any advice on this one? Thanks Info: The football stuff is just a simplifying example. In reality it is not possible to put both tables into one and have a new “team” column. The two tables have completely different structures, but I need something that matches the characteristics of this example.

You can do something like this:

If you like to keep records separate and not do the union.
Try query below

The UNION statement is your friend:

You can union the queries as long as the columns match.

You can combine data from the two tables, order by goals highest first and then choose the top two like this:

MySQL

SQL Server

If you only want Messi and Ronaldo

To ensure that messi is at the top of the result, you can do something like this:

Using union will help in this case.

You can also use join on a condition that always returns true and is not related to data in these tables.See below

select tmd .name,tbc.goals from tblMadr >

You can use UNION in this case

you jsut have to maintain order of selected columns ie id, name, games, goals in both SQLs

Not the answer you’re looking for? Browse other questions tagged sql select or ask your own question.

3 years, 8 months ago

site design / logo © 2019 Stack Exchange Inc; user contributions licensed under cc by-sa 3.0 with attribution required. rev 2019.4.24.33422

Ems order single querySQL: Two select statements in one query – Stack Overflow, ems order single query.

3 years, 8 months ago

ems order single query

EnableInternalCSP_request