Thursday, 15 September 2011

mysql - sql alternating column data -



mysql - sql alternating column data -

i'm building query in sql i'm collecting info on sales transactions, 2 of tables pull in client_notes. 1 client can have number of notes, not visa versa.

currently query looks like:

select client.name, client.email,..., client_notes.summary summary client client left bring together client_notes client_notes on client.client_id = client_notes.client_id

i want pull in reference_notes.summary clients. again, 1 client can have number of reference notes, not visa versa. want pull info in such way client_notes.summary entries show particular client , references_notes.summary entries show same client until moving on next client, both summaries displayed under same column named summary.

is possible in sql?

you can using union all. 2 select statements smashed together. first gets client_notes , sec gets reference_notes. things note union number , order of columns have same. info types have compatible well.

--get client_notes select client.name, client.email,..., client_notes.summary summary client client left bring together client_notes client_notes on client.client_id = client_notes.client_id union --get reference_notes select client.name, client.email,..., reference_notes.summary summary client client left bring together reference_notes reference_notes on client.client_id = reference_notes.client_id order client.name

mysql sql

No comments:

Post a Comment