Re: Select from multiple tables

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

 



Try DISTINCT


On Feb 29, 2012, at 10:28 PM, Amit Tandon wrote:

Dear Kranthi

You have to be clear what you decide especially when you are getting
multiple rows. To get just a single row you can use LIMIT clause.

But it would return only one row. Now you  have to decide which row.

So i think you decide on what you require and see how can you uniquely
identify that row
============
regds
amit

"The difference between fiction and reality? Fiction has to make sense."


On Thu, Mar 1, 2012 at 9:45 AM, Kranthi Krishna <kranthi117@xxxxxxxxx>wrote:

Hi,

The examples I saw were regarding cartesian join not inner join.  I
will read about inner joins. Also, the example i mentioned seems to be
a mistake. Both school and type will not be similar at the same time


Kranthi.
http://goo.gl/e6t3



On 1 March 2012 09:26, Kranthi Krishna <kranthi117@xxxxxxxxx> wrote:
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



Karl DeSaulniers
Design Drumm
http://designdrumm.com


--
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