2

I try to get data from two connected tables.

$query="SELECT a.*, (SELECT `city_id` FROM `staff-city`) as cities FROM `staff`  as a WHERE a.id=2";

i get the error:

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[21000]: Cardinality violation: 1242 Subquery returns more than 1 row'

It's logic, cause i have three cities for this id. The main goal is to get a row with id(2) from staff and join all data (city names) from staff-city - do it with one query and i need a final result such this:

array (
[id]=>value,
[..]=>values,
[cities]=>array(
    [0]=>2,
    [1]=>26
)

Thanks in advance!

Saharsh Shah
  • 28,687
  • 8
  • 48
  • 83
Dmitry Web
  • 29
  • 1
  • 5

1 Answers1

0
$query="SELECT a.*, b.city_id FROM staff a , staff-city b WHERE a.id=2"
Nana Partykar
  • 10,556
  • 10
  • 48
  • 77