A
A
atamahfmkey2018-06-22 12:29:01
SQL
atamahfmkey, 2018-06-22 12:29:01

SQL query. How to display data from two tables?

There is a request -

SELECT * FROM users as A WHERE ( A.cash BETWEEN 0 AND 79.99) AND A.tariff = '15';

The query displays all users from the users table who have a balance from 0 to 79.99 + tariff 15.
There is a phones table in which the phone numbers.
How to withdraw this
SELECT * FROM users as A WHERE ( A.cash BETWEEN 0 AND 79.99) AND A.tariff = '15';
a query to also display a phone from the phones table.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
nozzy, 2018-06-22
@atamahfmkey

SELECT A.*,
B.mobile
FROM users as A 
left join phones as B on B.login = A.login
WHERE ( A.cash BETWEEN 0 AND 79.99) AND A.tariff = '15';

A
atamahfmkey, 2018-06-22
@atamahfmkey

does not work.
I will add.
In the phones table, you need to display the mobile column. The users and phones table has identical login columns
This query displays everyone who has less than 0, and with phones.
Maybe that will be clearer.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question