CodeIgniter Forums
sql statement - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: sql statement (/showthread.php?tid=6923)



sql statement - El Forum - 03-17-2008

[eluser]mikeyhell[/eluser]
I'm rescripting and application and ran into an sql statement that's stumped me. Can someone help me understand what's going on here:

Code:
SELECT hotlead_flag, ve.*
FROM vendor_email_new ve
JOIN vendor_new using (email)
WHERE sent_email is null



sql statement - El Forum - 03-17-2008

[eluser]Jay Turley[/eluser]
[quote author="mikeyhell" date="1205813256"]I'm rescripting and application and ran into an sql statement that's stumped me. Can someone help me understand what's going on here:

Code:
SELECT hotlead_flag, ve.*
FROM vendor_email_new ve
JOIN vendor_new using (email)
WHERE sent_email is null
[/quote]

it is selecting hotlead_flag from the vendor_new table, and then selecting everything (ve.*) from the vendor_email_new table which has been aliased as ve. The tables are joined on the email column and the final criteria is if the vendor_new.sent_email column is null.

You can think of it this way (though I would probably enumerate the columns in the vendor_email_new table instead of using *):

Code:
SELECT
    vn.hotlead_flag, ve.*
FROM
    vendor_email_new ve
JOIN
    vendor_new vn
ON
    ve.email = vn.email
WHERE
    vn.sent_email IS NULL