Re: Select from multiple tables

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

Thanks for the input. I have seen some tutorials on joins, they all
suggest that MySql returns multiple rows

For example
--------------------------
School | Board 1
--------------------------
School | Board 1
-------------------------

Now if I have another one-to-many relation

-----------------------------------
School | Board 1 | Type 1
-----------------------------------
School | Board 1 | Type 2
-----------------------------------
School | Board 2 | Type 1
-----------------------------------
School | Board 2 | Type 2
------------------------------------

Using UNIQUE or something similar (like php.net/array_search ) causes
problems when Type 1 = Type 2 etc.

Kranthi.
http://goo.gl/e6t3



On 29 February 2012 19:43, Michael Stowe <mikegstowe@xxxxxxxxx> wrote:
> Select table1.item1, table2.item1 from table1 inner join table2 on table1.key = table2.foreignKey Where...
>
> You can also utilize left and right join to get data if there isn't a direct match (ie customer may not have ordered anything so you want to do a left join on orders as there may not be any order data but you still want to get the customer info).
>
> Hope that helps,
> Mike
>
>
>
> Sent from my iPhone
>
> On Feb 29, 2012, at 8:01 AM, Kranthi Krishna <kranthi117@xxxxxxxxx> wrote:
>
>> Hi all,
>>
>> Say I have an object like
>>
>> array
>>    schoolName => string
>>    board => array
>>         string
>>         string
>>
>> I generally create  two MySql tables
>>
>> schools: id PRIMARY KEY, SchoolName
>> boards: id FOREGIN KEY refers Table A(id), board
>>
>> and then do two selects. The problem is that, the number of selects
>> increase as the number of one-to-many relationships increase.
>>
>> Is there a better way to do this ? I have to extend an existing code
>> so I cannot use any libraries like doctrine
>>
>> Kranthi.
>> http://goo.gl/e6t3
>>
>> --
>> PHP Database Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux