Jump to content

Recommended Posts

SELECT * FROM names, labels WHERE names.name_id=labels.label_id .... etc

 

to my understanding one could rewrite that like

 

SELECT * FROM names LEFT JOIN labels ON names.name_id=labels.label_id

 

It just seems redundant to me to bother having such a function LEFT JOIN when the first query above is shorter.

 

Reguarding old thread: Made a mistake, wasn't thinking before i posted that this is mysql only.

Link to comment
https://forums.phpfreaks.com/topic/150424-left-join-same-as-regular-from/
Share on other sites

I also do it the same as your first way, but it said that

joins are suppose to be used to sort out data properly.

 

a join is suppose to gain the database information,

required properly via the rules that are asked for.

 

left join

right join

join  <<<< only ever used this one, suppose to be the most popular.

 

i find your example even hard to understand even theo ive seen thousands off examples.

 

SELECT * FROM names LEFT JOIN labels ON names.name_id=labels.label_id

 

i think the way you join database information is the way a person there self understands.

 

like i say i understand your first example better then your last.

 

 

if anybody got the time to explain, all the three joins available for mysql ill be very grateful, while on this topic.

 

have to be all explained in baby terms Theo.

You have to understand the purpose of joins.  When you have a deep application (for example on built in cakephp that are thousands of lines of code) standard queries can reach hundreds of lines potentially.  Joins are a very good way to help get data together from multiple tables under special conditions.

Look up: http://www.google.com/search?hl=en&rlz=1G1GGLQ_ENUS289&q=advanced+uses+for+sql+joins

To find out more details (the first few should be enough).

Neither of you know what you're talking about, and aren't really answering his question.

 

SELECT * FROM names, labels WHERE names.name_id=labels.label_id .... etc

 

This is an INNER JOIN essentially. It joins rows together where all both of the tables match the condition. Doing it by stating the join explicitly is favored to doing it like you do.

 

SELECT * FROM names LEFT JOIN labels ON names.name_id=labels.label_id

 

A LEFT JOIN (also called LEFT OUTER JOIN) joins table A and B where there are always rows on the "left" table (table A). If there aren't on the "right" table (table B) then the value in the result set will NULL. Then there is the RIGHT JOIN that's essentially the opposite of the LEFT JOIN.

 

There is also a FULL OUTER JOIN. If you recall set theory from your mathematics education then a FULL OUTER JOIN is the union of the result set of the LEFT OUTER JOIN and the result set of the RIGHT OUTER JOIN. I.e. put them together and remove the duplicates essentially. In math, if you have the two sets A={1,2,3} and B={3,4,5} then A∪B={1,2,3,4,5} (the union of A and B).

 

 

There are other joins as well. I would strongly recommend you to read the MySQL documentation on joins: http://dev.mysql.com/doc/refman/5.0/en/join.html or perhaps our tutorial on joins: http://www.phpfreaks.com/tutorial/data-joins-unions

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.